新聞中心
編寫一個多線程的java 程序
public class RunThread implements Runnable{
創(chuàng)新互聯(lián)建站堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站制作、成都網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的南康網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
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 + " 線程運行結(jié)束!");
}
public static void main(String[] args) {
RunThread a=new RunThread("小寫字母");
RunThread b=new RunThread("大寫字母");
a.onStart();
b.onStart();
//System.out.println(" 線程運譽棗行開始!");
}
JAVA多線程 編程題兩個案例,不會寫,求大神寫出代碼,萬分感謝,多線程還沒學(xué)。
/*
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");
}
}
案例一的兩種方法已經(jīng)寫好;現(xiàn)在有事,晚態(tài)宴弊上再把案例二代碼寫一下,應(yīng)該沒關(guān)系吧帆族祥乎!
抱歉,是一個線程類,我看錯了,晚上重發(fā)一下代碼!
網(wǎng)站名稱:多線程java編程代碼 多線程java編程代碼怎么寫
網(wǎng)頁鏈接:http://ef60e0e.cn/article/dspjhes.html