在Java Bean中Sleep
我的业务在JavaBean中,JSP调用这个JavaBean,由于业务计算比较耗时,JSP调用后,浏览器半天才能出来结果。于是把在JavaBean中加了线程,如下:
public class Test extends Thread { public void run() { Log.x().info("thread start"); try { for (int i = 0; i < 100; i++) { Log.x().info("sleep" + i); Thread.sleep(1000); } } catch (Exception e) { Log.x().info("Exp"); } Log.x().info("thread end"); } public static void go() { // Create and start the thread Thread thread = new Test(); Log.x().info("call thread"); thread.start(); }}