欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java线程的一段代码

程序员文章站 2022-07-15 15:17:52
...
public static void main(String[] args) throws Exception {
	ExecutorService threadpool = Executors.newFixedThreadPool(1);
	Callable r = new Callable() {
		@Override
		public String call() {
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			return "11111";
		}
	};
	FutureTask<String> f = new FutureTask<>(r);
	new Thread(f).start();
	System.out.println(f.get());
	System.out.println("end");
	
	Runnable r = new Runnable() {
		@Override
		public void run() {
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("runnable");
		}
	};
	
	Thread t = new Thread(r);
	t.start();
	LockSupport.unpark(t);
	System.out.println("hhh");
}