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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

執(zhí)行新的可運(yùn)行文件時(shí)丟失 ApplicationContext

執(zhí)行新的可運(yùn)行文件時(shí)丟失 ApplicationContext

瀟湘沐 2021-09-12 17:27:12
我知道我對(duì)這個(gè)春天的東西很陌生,但我一整天都被困在這個(gè)問題上。我不太喜歡提問,但也許我會(huì)得到一個(gè)想法。所以這是我的問題:我正在嘗試創(chuàng)建一個(gè)隊(duì)列來處理后端的內(nèi)容。我通過在組件類中創(chuàng)建一個(gè)靜態(tài) executorservice 并使用幫助方法來運(yùn)行它們來做到這一點(diǎn)。它似乎像我想要的那樣工作,當(dāng)我在類中連接時(shí),我可以進(jìn)入這些類,但是當(dāng)它們運(yùn)行時(shí),它們似乎丟失了應(yīng)用程序上下文(或者這只是我的猜測(cè))。我確信有更好的方法可以做到這一點(diǎn),但在我正在使用的自定義框架中,有許多功能對(duì)我不起作用。我沒有 spring-config.xml,不能使用@Configuration執(zhí)行器服務(wù)組件@Componentpublic class FifoComponent {public static ExecutorService executors = Executors.newSingleThreadExecutor();private static Lock lock = new ReentrantLock(true);public static void executeNewTestJob(int i) {    lock.lock();    OrderAllocationTestJob job = new OrderAllocationTestJob(i);    executors.execute(job);    lock.unlock();}}可運(yùn)行組件 - 請(qǐng)注意 appdateutils 有一個(gè)方法可以調(diào)用一個(gè)組件,該組件在我的典型 tomcat 環(huán)境中運(yùn)行良好@Componentpublic class OrderAllocationTestJob implements Runnable {int i;public OrderAllocationTestJob(int i) {    this.i = i;}@Overridepublic void run() {    try {        Thread.sleep(100);    } catch (InterruptedException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }    System.out.println("Asynchronous task " + i);    System.out.println(AppDateUtils.getCurrentTimeStamp());}}從 struts 2 操作(測(cè)試)調(diào)用我知道我可以從調(diào)用 appdateutils.gettime 方法    for (int i = 0; i < 50; i++) {        FifoComponent.executeNewTestJob(i);    }這是我最終得到的例外情況“范圍'請(qǐng)求'對(duì)于當(dāng)前線程無效”
查看完整描述

3 回答

?
一只甜甜圈

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊

我通過為我的可運(yùn)行對(duì)象擴(kuò)展 ConcurrentLinkedQueue 并將它們保存在我在 ServletContextListener 的 initialize 方法中實(shí)例化的管理器中解決了這個(gè)解決方案。通過覆蓋 ConcurrentLinkedQueue 的 offer() 方法來持續(xù)輪詢直到隊(duì)列為空,我能夠同步處理可運(yùn)行對(duì)象。

不幸的是,這會(huì)鎖定請(qǐng)求線程,直到 runnable 完成,我將不得不讓我的用戶密切關(guān)注它并讓我知道頁面是否最終運(yùn)行很長(zhǎng)時(shí)間,但至少在我的測(cè)試環(huán)境中,該過程似乎是亞秒即使我一次打 20 個(gè),所以我現(xiàn)在還好。

我仍然更喜歡從我的 Tomcat 容器執(zhí)行的 ExecutorService 但在請(qǐng)求范圍之外,但除非有人可以回答這個(gè)問題,否則我現(xiàn)在只好離開它



查看完整回答
反對(duì) 回復(fù) 2021-09-12
?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

“我相信有更好的方法可以做到這一點(diǎn)”

基于此,您需要在調(diào)用另一個(gè)線程之前創(chuàng)建/查找所有請(qǐng)求和會(huì)話范圍的組件。實(shí)際上,請(qǐng)求注入是線程本地的,無法在您的場(chǎng)景中工作。


查看完整回答
反對(duì) 回復(fù) 2021-09-12
?
寶慕林4294392

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

你看起來像那樣嗎?


@Component 公共類 AsynchronousThread 擴(kuò)展了 Thread {


public static final Logger LOGGER = LoggerFactory

        .getLogger(AsynchronousThread.class);


@Autowired

private Writer writer;



private BlockingQueue<IndexContextDTO> blockingQueue = new LinkedBlockingQueue<IndexContextDTO>(

        500);


/**

 * 

 */

public AsynchronousThread() {

    super("AsynchronousThread");

}



@PostConstruct

public void init() {

    Integer internalQueueSize = 100;

    this.blockingQueue = new LinkedBlockingQueue<>(internalQueueSize);

    this.start();

}



@Override

public void run() {


    while (true) {

        // Do stuff

    }

}



public void putInQueue(IndexContextDTO message) {

    try {

        this.blockingQueue.put(message);

    } catch (InterruptedException interruptedException) {

        // This exception will be thrown in very rare case.

        LOGGER.error("An error while putting message in the queue. "

                + message, interruptedException);

    }

}

}


查看完整回答
反對(duì) 回復(fù) 2021-09-12
  • 3 回答
  • 0 關(guān)注
  • 238 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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