public class TaskThread
{
String temp=infoGenerator();
String arr[]=str.split(" ",3);
Runnable customer1=new Customer(parseInt(arr[0]),arr[1],arr[2]);//create first customer
String temp=infoGenerator();
String arr[]=str.split(" ",3);
Runnable customer2=new Customer(parseInt(arr[0]),arr[1],arr[2]);//creates second customer
String temp=infoGenerator();
String arr[]=str.split(" ",3);
Runnable customer3=new Customer(parseInt(arr[0]),arr[1],arr[2]);//creates third customer
Thread thread1=new Thread(customer1);//adds customers to their own thread
Thread thread2=new Thread(customer2);
Thread thread3=new Thread(customer3);
thread1.start();
thread2.start();
thread3.start();
//很抱歉,没有解释问题,
我尝试使用多线程创建多个Customer对象,然后使用overriden run()
方法执行预期的结果。编译器使用start()
方法指定问题出在所有三行中,它提供了错误消息:错误:预期。
答案 0 :(得分:0)
您没有解释您要实现的目标,因此很难为您提供帮助,但是编译错误似乎是因为您正在尝试编写代码
thread1.start();
thread2.start();
thread3.start();
仅在类TaskThread
中,但不在方法中。您可以在类内部声明变量,但是对于代码和功能,您需要像这样的方法和函数:
public class TaskThread
{
// here declare your variables...
public void doSomething() {
thread1.start();
thread2.start();
thread3.start();
}
}