public class TT implements Runnable { int b = 100;
public synchronized void m1() throws Exception { // Thread.sleep(2000);
System.out.println("m11");
b = 1000; Thread.sleep(5000); System.out.println("m12"); }
public synchronized void m2() throws Exception {
System.out.println("m21");
Thread.sleep(2500);
b = 2000;
System.out.println("m22");
} public void run() { try {
System.out.println("run");
m1();
} catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) throws Exception { TT tt = new TT(); Thread t = new Thread(tt); t.start();//run(); tt.m2(); System.out.println(tt.b); }}请问为什么运行的结果是m21 run m22 m11 1000 m12
run()比m2()还慢运行????
解决方案 »
- 用ldap修改active dirctory 用户密码,SSL问题
- 急问各位大侠,谢谢
- 150分请大家帮忙说明下这个JSliderExamples
- 如何取得远程主机时间?
- 报错信息是package system does not exist,怎么改啊?
- 窗体中有三个并列放置JTextArea, 当把窗体最大化时, 怎样让它们也按照一个特定的比例缩放?
- 为什么dispose()或者hide()有时候会关闭或者隐藏不掉模式对话框,这是为什么?
- applet小问题,我却不能搞定
- 初学java,请推荐基本质量高的书籍,谢谢
- java与mysql数据库连接
- java 逻辑题
- 新手 求一个jsp项目源码 学习
线程同步问题
然后轮到t.start()去执行System.out.println("run");
每次都是main先使用一个时间片,然后才是启动的线程