 
2017-11-22 11:51
修改的测试代码
public class HfPartentVirtualAccountService {
    public static boolean flat=true;
    @Before(Tx.class)
    public HfPartentVirtualAccount selectTest() throws Exception{
        HfPartentVirtualAccount taskSdh = HfPartentVirtualAccount.dao.findFirst("select * from hf_partner_virtual_account where a_id = 1  for update");
        if(flat){
            flat = false;
            Thread.sleep(1000*5);
        }
        return taskSdh;
    }
}
public void test() throws Exception{
        HfPartentVirtualAccountService virtualAccountService = enhance(HfPartentVirtualAccountService.class);
        HfPartentVirtualAccountService.flat = true;
        Thread1 thread1 = new Thread1(virtualAccountService);
        FutureTask future1 = new FutureTask(thread1);
        new Thread(future1).start();
        Thread2 thread2 = new Thread2(virtualAccountService);
        FutureTask future2 = new FutureTask(thread2);
        new Thread(future2).start();
        Map ret = new HashMap();
        ret.put("thread1",future1.get().getStr("a_partner_name"));
        ret.put("thread2",future2.get().getStr("a_partner_name"));
        renderJson(ret);
    }
    class Thread1 implements Callable {
        HfPartentVirtualAccountService virtualAccountService;
        public Thread1(HfPartentVirtualAccountService virtualAccountService){
            this.virtualAccountService = virtualAccountService;
        }
        public HfPartentVirtualAccount call() throws Exception{
            System.out.println("=========线程1开始============");
            HfPartentVirtualAccount taskSdh = virtualAccountService.selectTest();
            System.out.println("=========线程1结束============");
            return taskSdh;
        }
    }
    class Thread2 implements Callable{
        HfPartentVirtualAccountService virtualAccountService;
        public Thread2(HfPartentVirtualAccountService virtualAccountService){
            this.virtualAccountService = virtualAccountService;
        }
        public HfPartentVirtualAccount call() throws Exception{
            System.out.println("=========线程2开始============");
            HfPartentVirtualAccount taskSdh = virtualAccountService.selectTest();
            System.out.println("=========线程2结束============");
            return taskSdh;
        }
    }
出现了传说中的事务等待,不然我这个for update没用啊,哈哈,结贴!
 
2017-11-22 11:49
已经解决了,看了jfinal的开发pdf找到了这一串内容
// 定义需要使用AOP的业务层类
public class OrderService {
// 配置事务拦截器
@Before(Tx.class)
public void payment(int orderId, int userId) {
// service code here
}
}
// 定义控制器,控制器提供了enhance系列方法可对目标进行AOP增强
public class OrderController extends Controller {
public void payment() {
// 使用 enhance方法对业务层进行增强,使其具有AOP能力
OrderService service = enhance(OrderService.class);
// 调用payment方法时将会触发拦截器
service.payment(getParaToInt("orderId"), getParaToInt("userId"));
}
}