-2
내 스레드가 디버거에 나타나지 않는 이유를 이해해 주시겠습니까? 음, main 메소드의 주석에서 볼 수 있듯이, Task 인스턴스의 perform() 메소드를 실행할 수 있습니다. 그러나 스레드를 시작하려고하면 시작되지 않습니다. 모든 중단 점은 Thrd의 run() 메서드가 호출되었음을 나타내지 않습니다. 당신은 단지 Thread
의 인스턴스를 생성스레드를 시작할 수없는 이유는 무엇입니까
public class ParallelThreads {
public static void main(String[] args) {
Task t = new Task("C:\\FilesToRead\\1.txt");
//System.out.println(t.perform()); // It works!
Thread thread = new Thread(t);
}
}
public class Thrd implements Runnable{
TaskWithResult task;
public Thrd(TaskWithResult task){
this.task = task;
}
@Override
public void run(){
task.perform();
}
}
public interface TaskWithResult {
long perform();
}
public class Task implements TaskWithResult, Runnable {
File fileToRead;
public Task(String file) {
fileToRead = new File(file);
}
long count = 0;
@Override
public void run(){
perform();
}
@Override
public long perform() {
...
return count;
}
}
하여 시작해야합니다()'... –
RTFM : http://docs.oracle. com/javase/6/docs/api/java/lang/Thread.html – Messa