File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes selecting frrom database in multithreaded environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "selecting frrom database in multithreaded environment" Watch "selecting frrom database in multithreaded environment" New topic

selecting frrom database in multithreaded environment

nikil shar
Ranch Hand

Joined: May 25, 2008
Posts: 116
hi all,
need some advise on multi-threading, i have a java class which extends Thread. Inside its run () method i want to go to the database and fetch some records and write them out to a flat file. I am not sure how to synchronise the code so when multiple threads are running at the same time the data that gets returned from the database doesnt get corrupted.
i don't have any sample code yet so apologies if the above is vague.

thanks in advance.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Your output is going to just one flat file? Then you'll want to prevent threads from trying to write to that file at the same time. You could have your working threads synchronize on something to prevent that, or you could use a producer-consumer model in which your "producers" are your working threads (the ones accessing the database) and the "consumer" is something which writes to that file.
wood burning stoves
subject: selecting frrom database in multithreaded environment
Similar Threads
Need an event in a client program
Intranet to Internet transfer
Leak Found Exception
Small SQL databases for JUNIT tests
Catching the content of drop down box