GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — javaCode/CallableDemo.java at master · Javajava1/javaCode Expand file tree/ Copy pathCallableDemo.javaMore file actions 27 lines (24 loc) · 829 Bytes / Copy pathCallableDemo.javaFile metadata and controls27 lines (24 loc) · 829 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 package edu.nwpu.zhao.Test; import java.util.concurrent.*; /** * @author:weilongzhao * @time:2021/7/15 16:22 * * 多线程已经有extants Thread 和Runnable 接口,为什么需要Callable 接口 */ class MyThread implements Callable<Integer>{ @Override public Integer call() throws Exception { System.out.println(Thread.currentThread().getName()+" come in"); TimeUnit.SECONDS.sleep(2); return 1024; } } public class CallableDemo { public static void main(String[] args) throws ExecutionException, InterruptedException { FutureTask<Integer> futureTask = new FutureTask<Integer>(new MyThread()); new Thread(futureTask,"AA").start(); System.out.println(Thread.currentThread().getName()+" come in"); System.out.println(futureTask.get()+100); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |