第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

線程返回和同步

線程返回和同步

手掌心 2022-06-08 17:36:33
我正在制作紙牌游戲應(yīng)用程序。我有 2 個線程:線程curr = 這里保存當(dāng)前線程(JavaFx 線程)線程proHs = 這是應(yīng)用程序的大腦,它通過接口運行方法我想停止線程proHs停止一秒鐘,直到我選擇這兩個按鈕中的一個mam nemam然后我必須返回true或false。我感謝任何建議或建議。謝謝!我試過無限循環(huán)public boolean biddingStep(int gt) { //above this method is @Override, I can't post this with it    System.out.println("  ");    System.out.println("I HAVE OR NOT PART");    try {        proHs.wait();    }    catch (Exception e) {        System.out.print(e);    }    panelLicitace.setVisible(true);    mam.setVisible(true);    nemam.setVisible(true);    return false;//there would be the resolution of button "mam" or "nemam"}編輯#1我想從你這里得到什么:public boolean biddingStep(int gt) { //above this method is @Override, I can't post this with it    System.out.println("  ");    System.out.println("I HAVE OR NOT PART");    panelLicitace.setVisible(true);    mam.setVisible(true);    nemam.setVisible(true);    // HERE a code i want    //1. stop proHS thread    //2. loop program, wait for input from 2 buttons    //3. return true or false}
查看完整描述

1 回答

?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗 獲得超8個贊

首先你需要了解wait()是Object類的方法,所以它就像一個特定的線程在等待一些與Object相關(guān)的動作。因此,如果在 proHs 線程下調(diào)用 bidStep (int gt)并且您想停止 proHs 線程,基本上要等到選擇特定按鈕然后您需要將等待放在某個對象上,通常它應(yīng)該是 Object需要采取一些行動。您需要在此處列出以下步驟:

  1. proHs 對象引用。

  2. 鎖定 proHs 對象。

  3. 調(diào)用 proHs.wait()。

從第二個線程您將執(zhí)行以下操作: 1. 在 buttonClickListener 第二個線程內(nèi)鎖定 proHs 對象
。) 2. 調(diào)用 proHs.notify()。

class InterfaceImpl {

    Thread proHs;

    boolean btnResponse;

    public boolean biddingStep(int gt) {

        System.out.println("  ");

        System.out.println("I HAVE OR NOT PART");

        panelLicitace.setVisible(true);

        mam.setVisible(true);

        nemam.setVisible(true);

        // HERE a code i want

        //1. stop proHS thread

        synchronized(proHs) {

            proHs.wait();

            //2. loop program, wait for input from 2 buttons

            //3. return true or false

            return btnResponse;

        }

    }   


    // This method should be called from another thread

    public boolean btnClickListener() { 

        btnResponse = true or false

        synchronized(proHs) {

            proHs.notify();

        }  

    }

}

這里 bidStep() 方法應(yīng)該在 btnClickListener() 之前調(diào)用,這樣一旦線程等待,另一個線程就會通知它。


查看完整回答
反對 回復(fù) 2022-06-08
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號