![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Thread
文章平均质量分 57
ld513508088
这个作者很懒,什么都没留下…
展开
-
Thread初识
1、 进程是一个静态的概念,比如exe或class文件;2、 在机器里实际运行的是线程;3、 线程是程序的不同的执行路径;4、 进程里一般含有一个主线程;5、 实现线程的两种方式:实现Runnable接口,继承Thread类;一般用前者这样线程类还可以实现其他的类6、 用start开启的线程不一定立马运行,要看计算机CPU如何调度;第一个例子:public原创 2012-12-12 15:07:46 · 307 阅读 · 0 评论 -
synchronized理解-------马士兵
知识点:synchronized锁住的是当前对象,没有锁的方法仍然可以执行public class TT implements Runnable { int a=100; public synchronized void method1(){ //锁住当前对象 try{ a=1000; Thread.sleep(5000);//子线程执行到这里睡眠,主线原创 2012-12-27 13:26:17 · 531 阅读 · 0 评论 -
PRIORITY of Thread
public class TestJoin { public static void main(String[] args) { MyThread myThread = new MyThread("one"); MyThread otherThread = new MyThread("other"); myThread.setPriority(Thread.NORM_PRIO原创 2012-12-14 15:02:06 · 433 阅读 · 0 评论 -
Thread.join()
1、join( ):合并线程,当前线程将等待出现其中的线程运行完之后再运行2、例子public class TestJoin { public static void main(String[] args) { //这里main线程是当前线程 MyThread myThread=new MyThread("other"); myThread.start(); try{原创 2012-12-14 14:46:33 · 333 阅读 · 0 评论 -
synchronized 理解
public class TT implements Runnable { int a=100; public synchronized void method1(){ try{ a=1000; Thread.sleep(5000); }catch(InterruptedException e){ e.printStackTrace(); }原创 2012-12-27 14:48:18 · 293 阅读 · 0 评论 -
初识线程同步
public class TestSynchronized implements Runnable { /** * @param args */ Timer timer = new Timer(); public static void main(String[] args) { TestSynchronized testSynchronized=new TestSy原创 2012-12-14 15:55:13 · 271 阅读 · 0 评论 -
synchrnoized 理解
public class TT implements Runnable { int a=100; public synchronized void method1(){ try{ a=1000; Thread.sleep(5000); }catch(InterruptedException e){ e.printStackTrace(); }原创 2012-12-27 14:31:14 · 401 阅读 · 0 评论 -
模拟线程死锁
public class TestDiedLock implements Runnable { static Object o2 = new Object(), o1 = new Object(); public int flag = 0; public void run() { System.out.println("flag=" + flag); if (flag ==原创 2012-12-27 10:57:52 · 290 阅读 · 0 评论 -
synchronized 理解
public class TT implements Runnable { int a=100; public synchronized void method1(){ try{ a=1000; Thread.sleep(2500); }catch(InterruptedException e){ e.printStackTrace(); }原创 2012-12-27 14:01:35 · 305 阅读 · 0 评论 -
Thread.interrupt方法
import java.util.Date;public class TestInterrupt { /** * @param args */ public static void main(String[] args) { Runner2 runner = new Runner2(); runner.start();//启动子线程 try { T原创 2012-12-12 16:04:26 · 339 阅读 · 0 评论 -
Thread.yeild( )
1、yield():Causes the currently executing thread object to temporarily pause and allow other threads to execute2、for example:public class TestJoin { public static void main(String[] args) { My原创 2012-12-14 14:55:19 · 595 阅读 · 0 评论