Tread
来源:互联网 发布:爬虫软件的作用 编辑:程序博客网 时间:2024/04/28 15:07
package cric.thread;
import java.util.TimerTask;
public class Threads {
MyThread myT;
public void run() {
// ///////创建线程///////
MyThread mt = new MyThread();
mt.setPriority(Thread.MAX_PRIORITY);
mt.setName("my thread");
// mt.setDaemon(true);
mt.start();
// ///////创建线程1///////
MyThread1 mt1 = new MyThread1();
// new Thread(mt1).setName("my thread1");
new Thread(mt1).start();
new Thread(mt1).start();
new Thread(mt1).start();
new Thread(mt1).start();
new Thread(mt1).start();
// ///////创建线程2///////
MyThread2 mt2 = new MyThread2();
// mt2.getThread().setName("my thread2");
mt2.getThread().start();
mt2.getThread().start();
mt2.getThread().start();
mt2.getThread().start();
int i = 0;
// while(true)
{
// if(i++==1000)break;
System.out.println("main: " + Thread.currentThread().getName());
// ////////最大与最小线程////////////
// System.out.println(Thread.MAX_PRIORITY+" "+Thread.MIN_PRIORITY);
}
mt.setPriority(Thread.MAX_PRIORITY);
// System.out.println("当前线程: "+Thread.currentThread());
// System.out.println("main: "+Thread.currentThread().getName());
}
public static void main(String[] args) {
Threads t = new Threads();
t.run();
//volatile k;
MyThread myT = new MyThread();
//myT.start();
}
class Times extends TimerTask{
@Override
public void run() {
//volatile int i;
}
}
}
class MyThread extends Thread {
/*
* public void run() { System.out.println("我的线程名字:"+getName());
* System.out.println("我的线程属性:"+getPriority());
* System.out.println("我的当前线程: "+currentThread());
* System.out.println("我的当前线程名字: "+getName());
* System.out.println("我的当前线程属性: "+getPriority()); }
*/
public void run() {
//while(true)
{
System.out.println("我的线程名字:" + getName());
System.out.println(toString());
yield();
}
}
}
class MyThread1 implements Runnable {
int in = 0;
long minPrime;
MyThread1() {
}
MyThread1(long minprime) {
minPrime = minprime;
}
public void run() {
// while(true)
{
System.out.println("A我的线程名字: in "
+ Thread.currentThread().getName() + in++);
System.out.println("A我的线程名字:" + toString());
Thread t = new Thread();
System.out.println("当前线程: " + t.currentThread().toString());
}
}
}
class MyThread2 {
int index = 0;
class innerThread extends Thread {
public void run() {
// while(true)
{
System.out.println("B我的线程名字:index " + getName() + index++);
System.out.println(toString());
}
}
}
Thread getThread() {
return new innerThread();
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jinwanmeng/archive/2010/10/23/5960744.aspx
- Tread
- Tread.Join()
- User Tread和Deamon Tread
- Servlet Tread tips
- Tread+delegate 操作UI
- Runnable&&Tread使用
- Tread 的一些例子说明
- android 中的Tread 、Handler、Looper
- Service 和 Tread 的区别?
- C++11 tread和锁
- C#的多线程 / Multi-Tread of C#
- Java Tread多线程(2)多线程安全问题
- Java Tread多线程(3)死锁
- Tread类和Runnable类两种简单实现双线程
- [Java] Tread.sleep() 电子表显示时期和时间
- Java Tread多线程(0)一个简单的多线程实例
- Java Tread多线程(1)实现Runnable接口
- eclipse as android jni 和 ndk以及调用过程--tread
- textarea的换行 htmlentities的用法
- 关于C++的函数模板问题
- 悬而未决:有可编辑未能启动的WIN系统注册表的图形界面工具吗?
- xml在IE中无法解析
- 秋季该喝什么茶
- Tread
- htmlspecialchars() 与 htmlspecialchars_decode()
- arm-linux编译osip,ortp-0.7.0,exosip2(转载)
- Struts2与下拉列表绑定的取值问题
- 如何解决phpMyAdmin最大2M文件限制问题
- 隐马尔可夫模型中的Viterbi算法
- 复杂指针读法
- Java线程同步
- IListHelper 实现IList到DataSet和DataTable的数据转换