Results 1 to 1 of 1
- 11-15-2011, 11:08 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
troubles using threadpool on amachine with linux
Hi,
I have written a program that runs on multiple threads. I wrote the program using NetBeans 7.0.1. When I run the program from NetBeans I get the following error
If I use a threadpool of size 1, the code works fine (despite the errror message), but if I select more threads the program just never starts (it does not crash/exit/fail/quit, it just sits there and does nothing. Below is is my Main.java class.Java Code:0 [main] INFO fish - There are 8 simulations to execute. 0 [main] INFO fish - 8 Simulations ready to run. 0 [main] INFO fish - Running with a thread pool of size = 1 16 [pool-1-thread-1] INFO [Repetition 0] - method run() in simulation started Exception in thread "main" java.util.concurrent.RejectedExecutionException at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1768) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:78) at fishmodel.Main.run(Main.java:76) at fishmodel.Main.main(Main.java:53)
Any help would be very very welcomed!
Java Code:public class Main { // Logger for IO static Logger logger = Logger.getLogger("fish"); public static void main(String[] args) throws java.io.IOException { CmdLineOptions options = new CmdLineOptions(); CmdLineParser parser = new CmdLineParser(options); parser.setUsageWidth(80); BasicConfigurator.configure(); // Logger levels: // WARN - almost nothing // INFO - a bit more // DEBUG - more // TRACE - everything logger.setLevel(Level.INFO); try { parser.parseArgument(args); } catch (CmdLineException e) { logger.error(e.getMessage()); logger.error("java -jar FishModel.jar [options...] arguments..."); parser.printUsage(System.err); System.exit(1); } Main main = new Main(); main.run(options); } public void run(CmdLineOptions options) throws java.io.IOException { // create the ArrayList<SimulationParameters> // this ArrayList has all informations that are necessary to run a simulation // all things such a s locations and names of input/output files // and model's rules for each simulation (e.g. mating random or non-random) ArrayList<SimulationParameters> mySimulationParameters = createSimulationToRun(options); logger.info(mySimulationParameters.size() + " Simulations ready to run."); // this sets how many simulations can be run simultaneously (one thread per processor) logger.info("Running with a thread pool of size = " + options.threads); ExecutorService pool = Executors.newFixedThreadPool(options.threads); // for every line of the ArrayList<SimulationParameters>, run the given simulation for(int i = 0; i < mySimulationParameters.size(); i++) { SimulationParameters params = mySimulationParameters.get(i); for (int j = 0; j < params.numberOfRepetitions; j++) { logger.trace("Submitting new simulation for execution."); try { pool.submit(new Simulation(params, j)); } catch (CloneNotSupportedException ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } } pool.shutdown(); } } public ArrayList<SimulationParameters> createSimulationToRun(CmdLineOptions options) throws java.io.IOException { ArrayList<SimulationParameters> sims = createSimulationFromOptions(options); if (options.simFileLocation != null) { try { sims.addAll(ExcelFile.readSimulationFile(options.simFileLocation)); } catch (Exception ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } } else { logger.warn("No simulation file was specified."); } logger.info("There are " + sims.size() + " simulations to execute."); return sims; } public ArrayList<SimulationParameters> createSimulationFromOptions(CmdLineOptions options) throws java.io.IOException { ArrayList<SimulationParameters> sims = new ArrayList<SimulationParameters>(); SimulationParameters sim = new SimulationParameters(); sim.simulationGroupID = options.simulationGroup; sim.startSimulationYear = options.startSimulationYear; sim.endSimulationYear = options.endSimulationYear; sim.numberOfRepetitions = options.numberOfRepetitions; sim.randomSeed = options.randomSeed; sim.populationID = options.populationID; sim.stockingDescription = options.stockingDescription; sim.needOfSpecialFish = options.needOfSpecialFish; sim.initialFishFileLocation = options.initialFishFileLocation; sim.stockedFishFileLocation = options.stockedFishFileLocation; sim.maxAge = options.maxAge; sim.maturityAge = options.maturityAge; sim.diagnosticLoci = options.diagnosticLoci; sim.populationAmongGrounds = options.populationAmongGrounds; sim.populationStructureRule = options.populationStructureRule; sim.differenceController = options.differenceController; sim.networkID = options.networkID; sim.multipleSpGrndPresent = options.multipleSpGrnd; sim.nodesAndFishFileLocation = options.nodesAndFishFileLocation; sim.linksFileLocation = options.linksFileLocation; sim.generalOutputFileLocation = options.generalOutputFileLocation; sim.alleleOutputFileLocation = options.alleleOutputFileLocation; sim.offspringIntrogressionfileLocation = options.offspringIntrogressionfileLocation; sim.ychOutputFileLocation = options.ychOutputFileLocation; // This seems like funny behavior but it helps clean things up if (options.simFileLocation == null) { sims.add(sim); } return sims; } }
Similar Threads
-
How to implement my own ThreadPool ??
By krishanu in forum New To JavaReplies: 6Last Post: 06-12-2011, 08:01 AM -
Image troubles
By Theodoreb in forum New To JavaReplies: 24Last Post: 07-14-2009, 12:41 AM -
[SOLVED] Windows Linux conflict - TrayIcon image not display in Linux
By Eranga in forum Advanced JavaReplies: 6Last Post: 04-08-2009, 04:05 AM -
Question about threadpool
By waleed.k.omran in forum Threads and SynchronizationReplies: 1Last Post: 02-25-2009, 02:48 PM -
Using jakarta-commons threadpool (Tomcat) through JNDI
By zrrbite in forum Advanced JavaReplies: 0Last Post: 12-14-2007, 12:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks