2017-02-09 4 views
-8

Exception in thread "main" java.lang.IllegalArgumentException
at java.util.concurrent.ThreadPoolExecutor.(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.(Unknown Source)
at java.util.concurrent.Executors.newFixedThreadPool(Unknown Source)
at alerts.email.VinrEmailNotification.main(VinrEmailNotification.java:50)Executors.newFixedThreadPool()からのIllegalArgumentException

これは私の例外です。どうすれば解決できますか?これは私のコードです:

package alerts.email; 

import java.io.FileInputStream; 
import java.util.Properties; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import org.apache.log4j.Logger; 
import org.apache.log4j.PropertyConfigurator; 
import alerts.utils.Constants; 

/** The main entry point for the application which 
* creates a pool of threads for probing the 
* MessagesInTable, messages_sent_table and the 
* retrytable and uses the Java 5 Executor service 
* to run all the threads in the pool as parallel 
* tasks 
* 
* @author Sunil Tuppale 
* @date July-19-2010 
* @version 1.0 
*/ 

public class VinrEmailNotification {  

    static final Logger logger = Logger.getLogger(VinrEmailNotification.class);  
    public static void main(String[] args) {     
     Properties logProperties = null;   
     try {    //settings for logging    
      String fileName = System.getenv("LOG_PROPERTIES_FILE"); 
      if (fileName == null) 
       fileName="vinralerts.properties"; 
      logProperties = new Properties(System.getProperties()); 
      logProperties.load(new FileInputStream(fileName)); 
      PropertyConfigurator.configure(logProperties); 
      logger.debug("Logging initialized in VinrEmailNotification class ");   
     } catch(Exception e) { 
      e.printStackTrace(); 
     }   
     /*   
     * create a thread pool with four threads 
     */   
     int THREAD_POOL_SIZE = ConnectionPoolProvider.getInstance().getThreadPoolSize(); 
     ExecutorService messagesInTableTPExecSvc = Executors.newFixedThreadPool(THREAD_POOL_SIZE); 
     //ExecutorService messagesSentTableTPExecSvc = Executors.newFixedThreadPool(Constants.THREAD_POOL_SIZE); 
     //ExecutorService retryTableTPExecSvc = Executors.newFixedThreadPool(Constants.THREAD_POOL_SIZE); 
     /*   
     * place four tasks in the work queue for the thread pool   */ 
     for(int i = 0; i < THREAD_POOL_SIZE; i++) { 
      messagesInTableTPExecSvc.execute(new MessagesInTableProbe(i)); 
      //messagesSentTableTPExecSvc.execute(new MessagesSentTableProbe(i)); 
      //retryTableTPExecSvc.execute(new RetryTableProbe(i)); 
     } 
     /* 
     * prevent other tasks from being added to the queue 
     */   
     messagesInTableTPExecSvc.shutdown(); 
     //messagesSentTableTPExecSvc.shutdown() 
     //retryTableTPExecSvc.shutdown(); 
     //ConnectionPoolProvider.getInstance().getDataSource().release(); 
    } 
} 
+0

[コンパイルエラー:不正な式の開始]の可能な複製(http://stackoverflow.com/questions/7680528/compile-error-illegal-start-of-expression) –

+0

フォーマットについてはどうですか? – eol

+2

コードを投稿する前に、常にフォーマットしてください。今読むことは不可能です。 @SalmaanC番号: – BackSlash

答えて

6

つまり、THREAD_POOL_SIZEは0またはマイナスです。 Executors.newFixedThreadPool(int)のドキュメントから

Throws:

IllegalArgumentException - if nThreads <= 0

明らかに解決策はConnectionPoolProvider.getInstance().getThreadPoolSize()は正の数(少なくとも1)を返すことを確認することです。あなたはそれをどうやって、私はあなた自身のコードなので、あなたが一番よく知っていると信じています。また、プロバイダが有効な値を提供しない場合は、デフォルト値(たとえば、1)を使用できます。

関連する問題