摘要: public class Demo3_Thread { public static void main(String[] args) { /* * 继承Thread类 */ new Thread() { //1.继承Thread public void run() { //2.重写run方法 for 阅读全文
posted @ 2019-03-11 17:03 幻音坊-女帝 阅读(297) 评论(0) 推荐(0)
摘要: 实现Runnable的原理 1.看Thread类的构造函数,传递了Runnable接口的引用 2.通过 init()方法找到传递的target给成员变量的target赋值 3.查看run方法,发现run方法中有判断,如果target不为null就会调用Runnalbe接口子类对象的run方法 实现多 阅读全文
posted @ 2019-03-11 16:49 幻音坊-女帝 阅读(893) 评论(0) 推荐(0)
摘要: public class Demo2_Thread { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub MyRunnable myRunna 阅读全文
posted @ 2019-03-11 16:27 幻音坊-女帝 阅读(331) 评论(0) 推荐(0)
摘要: public class Demo1_Thread { public static void main(String[] args) throws InterruptedException { Demo demo = new Demo(); //4.创建Thread类的子类对象 demo.start 阅读全文
posted @ 2019-03-11 14:17 幻音坊-女帝 阅读(225) 评论(0) 推荐(0)
摘要: /*** 饿汉式**/class Singleton { //1.私有构造,其他类就不能访问该构造方法了 private Singleton () {}; //2.创建本类对象 private final static Singleton singleton = new Singleton(); / 阅读全文
posted @ 2019-03-11 13:34 幻音坊-女帝 阅读(91) 评论(0) 推荐(0)