public interface Runnable
{voidrun();}
Runnable r =()->{task code};
2.从这个Runnable构造一个Thread对象
var t = new Thread(r);
3.启动线程
t.start();
综合
Runnable r =()->{
try
{for(int i =0; i < STEPS; i++){double amount = MAX_AMOUNT * Math.random();
bank.transfer(0,1, amount);
Thread.sleep((int)(DELAY * Math.random()));}}catch(InterruptedException e){}};
var t = new Thread(r);
t.start();
Runnable r =()->{
try
{...while(!Thread.currentThread().isInterrupted()&& more work to do){do more work
}}catch(InterruptedException e){// thread was interrupted during sleep or wait}
finally
{
cleanup,if required
}// exiting the run method terminates the thread}