通过Interface的Runnable实现多线程的Yield,含setName,getName
2016-05-10 21:09
471 查看
public class TestThreadYield { public static void main(String[] args) { SubThread subThread_1 = new SubThread("subThread_1"); SubThread subThread_2 = new SubThread("subThread_2"); Thread th1 = new Thread(subThread_1); Thread th2 = new Thread(subThread_2); th1.start(); th2.start(); } } class SubThread implements Runnable{ private String name; SubThread(String str){ name = str; } public void run(){ Thread.currentThread().setName(name); for(int i = 0; i <= 100; i++){ System.out.println(Thread.currentThread().getName() + ": " + i); if(i%10 == 0){ Thread.currentThread(); Thread.yield(); } } } }
相关文章推荐
- C#线程间不能调用剪切板的解决方法
- C#线程同步的三类情景分析
- C#获取进程或线程相关信息的方法
- 简单对比C#程序中的单线程与多线程设计
- C#停止线程的方法
- C#子线程更新UI控件的方法实例总结
- C#线程队列用法实例分析
- C#中yield return用法分析
- C++使用CriticalSection实现线程同步实例
- 基于C++实现的线程休眠代码
- VB读取线程、句柄及写入内存的API代码实例
- C#网络编程基础之进程和线程详解
- C#通过Semaphore类控制线程队列的方法
- C#多线程处理多个队列数据的方法
- C#实现线程安全的简易日志记录方法
- C#中线程同步对象的方法分析
- C# yield关键字详解
- c# yield提高代码性能和可读性
- ASP.NET线程相关配置
- 浅析linux环境下一个进程最多能有多少个线程