搞了几天终于把eclipse向visual studio靠近了一点点。visual studio有很多强大功能能够提高代码编写速度与质量,不过eclipse也有更多“怪异”的代码提示功能,主要是eclipse能够更“自由”的修改,“更”容易“适应”编程者的特殊要求~
在为eclipse增加可视化的插件时貌似发现:SWTDesigner与VE不兼容~~
去掉SWTDesigner后就能正常使用了~~~
以前以为多线程技术多高级的,结果完全是CUP的功劳@@!
小记一哈吧:入口
- package com;
- public class ThreadMain
- {
- /**
- * @param args
- */
- public static void main(String[] args)
- {
- //共有资源
- Multi multi=new Multi();
- Thread t1 = new Thread( multi, "一号窗口:");
- Thread t2 = new Thread( multi, "二号窗口:");
- Thread t3 = new Thread( multi, "三号窗口:");
- /**
- * 注释:Ctrl+7,很拉风哦!
- */
- // t1.setName("一号窗口:");
- // t2.setName("二号窗口:");
- // t3.setName("三号窗口:");
- t1.start();
- t2.start();
- t3.start();
- //for中i++不见了?
- for (int i = 0; i < 10; )
- {
- if (i==5)
- {
- //强制运行
- try
- {
- t1.join();
- t2.join();
- t3.join();
- }
- catch (Exception e)
- {
- System.out.print("搞错了!");
- }
- }
- System.out.println(Thread.currentThread().getName()+"主线(vip):"+ ++i);
- }
- }
- }
线程:
- package com;
- public class Multi implements Runnable
- {
- /**
- * 语句块的执行顺序:静态块》构造块》构造方法
- */
- public Multi()
- {
- System.out.println("我是构造方法!");
- }
- {
- System.out.println("我是构造块,我先与/"构造方法/"执行!");
- }
- static
- {
- System.out.println("我是静态块,我先于/"构造块/"执行!");
- }
- // 总共10张票
- private int count = 10;
- // 同步售票synchronized
- public void run()
- {
- while (count>0)
- {
- //单刀赴会
- synchronized (this)
- {
- setMulti();
- }
- }
- }
- private void setMulti()
- {
- //Ctrl+i:自动缩进
- if (count>0)
- {
- //选择try/catch包围方式自动生成
- try
- {
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- System.out.println(Thread.currentThread().getName() + count--);
- }
- }
- }
VIP售票到8张后,强制售完普通票,再销售VIP票,输出窗口如下: