0
下面是代碼,我需要爲2個不同的線程調用2個運行方法,可以這樣做。請幫忙。如何在一個java文件中調用兩個運行方法
public class QuestionList extends ListActivity implements Runnable {
//This below thread will call the run method
Thread thread = new Thread(QuestionList.this);
thread.start();
//can i have one more thread which call run1() method any idea
}
public void run() {
}
anInstanceOfBehaviourA你將如何在父線程中爲Thread創建一個子實例threadA = new Thread(anInstanceOfBehaviourA); threadA.start(); – max
我編輯了我的答案以向您展示。另一種方法是讓'類BehaviourA擴展線程'而不是'類BehaviourA實現Runnable'。這樣你創建一個'Thread t = new BehaviourA()',你可以調用't.start();'。這是我在大多數情況下的做法。我使用'implements Runnable'來儘可能地接近你的問題。 – Shlublu