的主要問題是,內「//做大量的下方東西」爲什麼誰最初寫這個檢查Java線程暫停,結束優雅並中止
if (stopscript)
return;
的人會實際上什麼幫助? Obs的stopscript()調用不會保證線程將被停止?當我讀到像http://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html這樣的東西時,我並沒有得到實際完成工作的地方。在他們的run()方法中,我不確定在哪裏插入要完成的實際工作。
我有一個類觀測數據中,我有一個本地類的編劇和使用它像這樣:
Scripter sscript;
Thread scriptthread;
它具有以下(不整類),只是它位::
實例化的編劇的內觀測值:
sscript = new Scripter(...);
scriptthread = new Thread(exesscript);
Obsrunning = true;
scriptthread.start();
這些是OB的其它方法被點擊停止或結束按鈕時被調用。
public void stopscript()
{
sscript.stopscript();
if (obssequencepaused)
{
sscript.resumescript();
JBpause.setText("PAUSE");
}
sscript = null;
}
public void endscript()
{
sscript.endscript();
if (obssequencepaused)
{
sscript.resumescript();
JBpause.setText("PAUSE");
}
}
的編劇類信息...
public class Scripter implements Runnable
{
@Override
public void run()
{
//does lots of stuff
}
final public void stopscript()
{
this.stopscript = true;
scriptthread.interrupt();
}
final public void pausescript()
{
this.pausescript = true;
}
final public void resumescript()
{
this.pausescript = false;
}
// sets parameters so loops should just fall through and main run() finishes
final public void endscript()
{
endscript = true;
numpositions = 0;
firstRepeats = 1;
repeats = 1;
}
}
問題:這段代碼是否運行了一個GUI庫,如Swing(我看到你正在調用'setText(...)')?此外,您還需要了解Java命名約定並嘗試堅持使用它們,特別是在發佈其他人(我們!)的代碼來閱讀,審閱,理解和幫助您時,由於不遵守這些規則,您會使其更難爲了我們。請注意,變量和方法名稱應以小寫字母和類名開頭,並帶有大寫字母。 –
如果是我的,我會在這段代碼中改變很多。我可能會或可能不會這樣做。這個代碼不是傳統的。對不起,如果這對你們來說更加困難,並且感謝你的嘗試。 – evernoob