日期:2014-05-20  浏览次数:21247 次

java如何读取properties中的设置的int型数据
Java code
package test;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.Properties;
public class TestThreadPool {

    private static int produceTaskSleepTime ;
    
    private static int produceTaskMaxNumber ;

    
    
    public static void main(String[] args) {

        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("Config.properties");   
          Properties p = new Properties();   
          try {   
           p.load(inputStream);   
          } catch (IOException e1) {   
           e1.printStackTrace();   
          }  
        // 构造一个线程池
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(2, 4, 3,
                TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3),
                new ThreadPoolExecutor.DiscardOldestPolicy());

        for (int i = 1; i <= p.getProperty(produceTaskMaxNumber); i++) {
            try {
                String task = "task@ " + i;
                System.out.println("创建任务并提交到线程池中:" + task);
                threadPool.execute(new ThreadPoolTask(task));

                Thread.sleep(p.getProperty.(produceTaskSleepTime));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}


------解决方案--------------------
propreties 配置的属性值,不需要分号呀

produceTaskSleepTime = 2;
produceTaskMaxNumber = 10;

后面的分号去掉