public class Run implements Runnable{
@Override
public void run() {
String threadName = Thread.currentThread().getName();
System.out.println("当前线程 "+threadName);
}
public static void main(String[] args) {
new Thread(new Run()).start();
}
}
public class Run extends Thread{
@Override
public void run() {
String threadName = Thread.currentThread().getName();
System.out.println("当前线程 "+threadName);
}
public static void main(String[] args) {
new Thread(new com.kongdechang.stu.Run()).start();
}
}
public class Run {
public static void main(String[] args) {
new Thread(()->{
String threadName = Thread.currentThread().getName();
System.out.println("当前线程 "+threadName);
}).start();
new Thread(new Runnable() {
@Override
public void run() {
String threadName = Thread.currentThread().getName();
System.out.println("当前线程 "+threadName);
}
});
}
}
public class Run implements Callable<String> {
@Override
public String call() throws Exception {
String threadName = Thread.currentThread().getName();
System.out.println("当前线程 "+threadName);
return threadName;
}
public static void main(String[] args) throws ExecutionException, InterruptedException {
Callable<String> callable = ()->{
String threadName = Thread.currentThread().getName();
System.out.println("当前线程 "+threadName);
return threadName;
};
ExecutorService es = Executors.newFixedThreadPool(2);
es.submit(new Run());
es.submit(new Run());
es.submit(new Run());
es.submit(callable);
Future<String> future = es.submit(callable);
es.shutdown();
System.out.println(future.get());
}
}