当前位置: 技术问答>java相关
关于线程的问题???
来源: 互联网 发布时间:2015-08-02
本文导语: 我才学Java时间不长,刚刚接触线程的问题,所以请各位帮帮忙。看看我下面的程序。我在init()中改了线程的优先级,但我在实际运行中却看到他们还是同时运行的,theThreads[x].setPriority(Thread.MIN_PRIORITY +x);根本没起...
我才学Java时间不长,刚刚接触线程的问题,所以请各位帮帮忙。看看我下面的程序。我在init()中改了线程的优先级,但我在实际运行中却看到他们还是同时运行的,theThreads[x].setPriority(Thread.MIN_PRIORITY +x);根本没起作用,这是为什么?请帮忙解决一下。以下是源码
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Frame;
import Threader;
public class GreatRace extends java.applet.Applet implements Runnable{
Threader theRacers[];
static int racerCount=3;
Thread theThreads[];
Thread thisThread;
static boolean inApplet=true;
int numberofThreadsAtStart;
public void init(){
numberofThreadsAtStart=Thread.activeCount();
setLayout(new GridLayout(racerCount,1));
theRacers=new Threader[racerCount];
theThreads=new Thread[racerCount];
for(int x=0;x
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Frame;
import Threader;
public class GreatRace extends java.applet.Applet implements Runnable{
Threader theRacers[];
static int racerCount=3;
Thread theThreads[];
Thread thisThread;
static boolean inApplet=true;
int numberofThreadsAtStart;
public void init(){
numberofThreadsAtStart=Thread.activeCount();
setLayout(new GridLayout(racerCount,1));
theRacers=new Threader[racerCount];
theThreads=new Thread[racerCount];
for(int x=0;x