![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
多线程
文章平均质量分 75
qq_37714601
这个作者很懒,什么都没留下…
展开
-
Java多线程之两种启动线程方式
启动线程有两种方式,第一种是extends Thread,第二种是implements Runnable.代码如下:继承Thread:public class MyThread extends Thread{ public String name; public MyThread(String n){ name = n; } public void原创 2017-03-01 17:33:35 · 432 阅读 · 0 评论 -
Java多线程之run()与start()
public class MyThread extends Thread{ public String name; public MyThread(String n){ name = n; } public void run(){ for (int i = 1; i <= 3; i++) { System.out.println(name+" "+i); }原创 2017-03-01 17:09:28 · 199 阅读 · 0 评论 -
Java多线程之知识点
1.main方法结束不耽误线程进度,线程可以继续执行至线程内任务结束。2.thread.sleep()可以休眠线程,例如thread.sleep(1000)可以休眠线程1秒,但是可以被thread.interrupt()打断。3.thread.setPriority() 可以设置线程优先级,主线程优先级为5,然而并非优先级高就可以先执行,仍旧取决于CPU资源分配。原创 2017-03-01 19:59:01 · 241 阅读 · 0 评论 -
Java多线程之互斥
The properites of Mutex solution:Mutual exclusion: only one process may be active in its critical section at a time.No deadlock: if one or more processes are trying to enter their critical sec原创 2017-03-02 16:48:06 · 217 阅读 · 0 评论 -
Java多线程之Synchronized应用在static和非static方法上的区别
同步static方法:public class Bank implements Runnable{ static int money = 2700; //注意区别 public static synchronized void Withdraw() { //public synchronized void Withdraw() { for(int i=0; i<3;i++){原创 2017-03-03 18:20:56 · 362 阅读 · 0 评论