Results 1 to 2 of 2
Thread: Question about threadpool
- 02-24-2009, 12:58 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
Question about threadpool
Hi
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, 02: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.
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
Question
By kenrocks in forum AWT / SwingReplies: 3Last Post: 12-09-2008, 05:07 AM -
Question
By ayoood in forum New To JavaReplies: 16Last Post: 05-21-2008, 02:23 PM -
JNI question
By javaplus in forum New To JavaReplies: 0Last Post: 12-24-2007, 10:18 AM -
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