
多线程
XCG123456789
这个作者很懒,什么都没留下…
展开
-
线程同步之synchronized
说明 synchronized:修饰成员方法锁对象是当前(对象实例锁)(this)、修饰静态方法锁对象是(类对象锁)(Test.class),一定要注意是否锁住的是同一个对象锁连判断是否存在互斥 代码示例 class Test{ private int count=0; public synchronized void increment(){ System.out.println("------------锁对象是this --- 当前调用方法的对象");原创 2021-09-08 15:20:18 · 140 阅读 · 0 评论 -
JAVA 线程基础
一、线程创建的三种方式 1、继承Thread Thread t = new Thread(){ @Override public void run() { System.out.println(""); } }; t.setName(“T1”); t.start(); 2、实现Runnable 接口 Runnable target = new Runnable() { @Override public void run() { System.out.println(“xx”); } }; Thread t原创 2021-09-07 17:51:13 · 100 阅读 · 0 评论