`
文章列表
线程同步: synchronized的使用 public class TestThread implements Runnable { Timer timer = new Timer(); public static void main(String[] args) { TestThread test = new TestThread(); Thread t1 = new Thread(test); Thread t2 = new Thread(test); t1.setName("t1"); t2.setName("t2&q ...
编写一个线程有两种方法,一种是实现Runnable接口,另一种方法是继承Thread类。 下面是实现Runnable接口的方法: public class TestThread { public static void main(String[] args) { Runner r1 = new Runner(); Thread t = new Thread(r1); t.start(); for(int i=0; i<100; i++) { System.out.println("main" + i); } } ...
Global site tag (gtag.js) - Google Analytics