189 8069 5689

多线程java编程代码 多线程java编程代码怎么写

编写一个多线程的java 程序

public class RunThread implements Runnable{

创新互联建站坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站制作、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的南康网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

String name;

Thread runner;

static boolean bool=true;

public RunThread(String threadName) {

name=threadName;

}

public void onStart()

{

runner = new Thread(this);

runner.setName(name);

runner.start();

}

public void run() {

String name=Thread.currentThread().getName();

System.out.println(name + " 线程运行开始!");

int index=0;

if(name.equals("小写字慎虚拍母"宽羡))

index='a';

else if(name.equals("大写字母"))

index='A';

while(!bool);

bool=false;

for(int i=index;i26+index;i++)

System.out.print((char)i+" ");

System.out.println();

bool=true;

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.println(name + " 线程运行结束!");

}

public static void main(String[] args) {

RunThread a=new RunThread("小写字母");

RunThread b=new RunThread("大写字母");

a.onStart();

b.onStart();

//System.out.println(" 线程运誉枣行开始!");

}

JAVA多线程 编程题两个案例,不会写,求大神写出代码,万分感谢,多线程还没学。

/*

class A extends Thread

{

public void run()

{

try

{

Thread.sleep(1000);

}catch(Exception e)

{

System.out.println("A ERROR!");

}

System.out.println("AAAA");

}

}

class B extends Thread

{

public void run()

{

try

{

Thread.sleep(2000);

}catch(Exception e)

{

System.out.println("B ERROR!");

}

System.out.println("BBBB");

}

}

class C extends Thread

{

public void run()

{

try

{

Thread.sleep(3000);

}catch(Exception e)

{

System.out.println("C ERROR!");

}

System.out.println("CCCC");

}

}

public class Test_1

{

public static void main(String[] args)

{

A a = new A();

B b = new B();

C c = new C();

a.start();

b.start();

c.start();

}

}*/

public class Test_1

{

public static void main(String[] args)

{

A a = new A();

B b = new B();

C c = new C();

Thread ta = new Thread(a);

Thread tb = new Thread(b);

Thread tc = new Thread(c);

ta.start();

tb.start();

tc.start();

}

}

class A implements Runnable

{

public void run()

{

try

{

Thread.sleep(1000);

}catch(Exception e)

{

System.out.println("A ERROR!");

}

System.out.println("AAAA");

}

}

class B implements Runnable

{

public void run()

{

try

{

Thread.sleep(2000);

}catch(Exception e)

{

System.out.println("B ERROR!");

}

System.out.println("BBBB");

}

}

class C implements Runnable

{

public void run()

{

try

{

Thread.sleep(3000);

}catch(Exception e)

{

System.out.println("C ERROR!");

}

System.out.println("CCCC");

}

}

案例一的两种方法已经写好;现在有事,晚态宴弊上再把案例二代码写一下,应该没关系吧帆族祥乎!

抱歉,是一个线程类,我看错了,晚上重发一下代码!


网站题目:多线程java编程代码 多线程java编程代码怎么写
网站URL:http://cdxtjz.cn/article/dspjhes.html

其他资讯