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

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

Java 8:聲納兼容服務(wù)器套接字

Java 8:聲納兼容服務(wù)器套接字

慕尼黑8549860 2023-10-12 16:50:26
下面是我的run()服務(wù)器套接字線程,它將作為Executors.newWorkStealingPool().submit(() -> mainServer.run());并接受客戶端連接運(yùn)行。它運(yùn)行良好,但Sonar抱怨它的Bug類型Loops should not be infinite (squid:S2189)    class MainServer {    private final ServerSocket serverSocket;        private final boolean checkClientCerts;    private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(MainServer.class.getName());    private final int threadPoolSize;    private boolean running;    private ExecutorService executorService;     MainServer(int port, boolean checkClientCerts, int threadPoolSize, InetAddress bindAddress) throws IOException {        LOG.debug("Locating server socket factory for SSL...");        SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();        LOG.debug("Creating a server socket on port " + port);        SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port, 0, bindAddress);                this.checkClientCerts = checkClientCerts;        this.threadPoolSize = threadPoolSize;    }    void run() {        running = true;        DefaultThreadFactory threadFactory = new DefaultThreadFactory("SSLHandshake");        executorService = new ShutdownThreadPoolExecutor(threadPoolSize,threadFactory);        while (running) {            Socket clientSocket;            try {                clientSocket = serverSocket.accept();                MainServerHandshakeThread handshakeThread = new MainServerHandshakeThread(clientSocket, this);                                executorService.submit(handshakeThread);            } catch (IOException ex) {                LOG.error("Error accepting connection",ex);            }        }    }    public void shutdown() {        LOG.info("Stopping main server...");        running = false;        try {            if (serverSocket!=null) {                serverSocket.close();            }        } catch(IOException ex) {            LOG.debug("Failed to close socket",ex);        }有人可以幫助我如何優(yōu)化上述代碼塊以消除聲納投訴嗎?
查看完整描述

1 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個贊

將您標(biāo)記runningvolatile.

volatile將變量標(biāo)記為可由其他線程更改1。這意味著優(yōu)化器(或代碼分析器,如 SonarQube)不能假設(shè)其他線程修改此類變量。在您的示例中,這兩個都可以假設(shè)never Changes,從而將您的代碼標(biāo)記為具有無限循環(huán)。

volatile如果變量可以被其他線程訪問和修改,則應(yīng)該將變量標(biāo)記為。


1由用戶207421更正。



查看完整回答
反對 回復(fù) 2023-10-12
  • 1 回答
  • 0 關(guān)注
  • 89 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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