• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

selecting frrom database in multithreaded environment

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic