Results 1 to 2 of 2
Thread: Question about threadpool
- 02-24-2009, 01:58 PM #1Member
- Join Date
- Feb 2009
- Rep Power
Question about threadpool
I'm developing a program that read from text file line by line and for each line it create a new thread for it and insert the record into database
ThreadPoolExecutor executer = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadPoolSize);
My question is how i can control the insertion of the records?? since I have two types of records insert or update and in the text file i want it to move in sequance not randomly.
so,how i can control the threadpool???
- 02-25-2009, 03:48 PM #2
Unless you have some really exotic reason to use threads here, *don't*. Read a line from the text file, write it to the database, loop.
If you *must* use threads, you should have only two, one to read the text file, and one to update the database. You will need to use a synchronized object like Vector to hold the lines read in one thread until the other thread writes them to the database.
If you have more than one database thread, you will have to either synchronize use of one connection, or you will have to create a connection for each thread. Either way makes no sense.
- By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 09:49 AM
- By kenrocks in forum AWT / SwingReplies: 3Last Post: 12-09-2008, 06:07 AM
- By ayoood in forum New To JavaReplies: 16Last Post: 05-21-2008, 02:23 PM
- By javaplus in forum New To JavaReplies: 0Last Post: 12-24-2007, 11:18 AM
- By zrrbite in forum Advanced JavaReplies: 0Last Post: 12-14-2007, 01:47 PM