Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Red face 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???

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    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

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. Question
    By kenrocks in forum AWT / Swing
    Replies: 3
    Last Post: 12-09-2008, 05:07 AM
  3. Question
    By ayoood in forum New To Java
    Replies: 16
    Last Post: 05-21-2008, 02:23 PM
  4. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 10:18 AM
  5. Using jakarta-commons threadpool (Tomcat) through JNDI
    By zrrbite in forum Advanced Java
    Replies: 0
    Last Post: 12-14-2007, 12:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •