Results 1 to 2 of 2
  1. #1
    snehalkgandhi is offline Member
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Smile Writing into a File in a Multi Threaded app.

    Hi,
    In my application, there are multiple threads and each thread writes into the LOG file. How will i know which thread wrote which line?

    Please let me know on this..

    Thanks in Advance
    Snehal Gandhi

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    Firstly, I'd advise not literally trying to have any old thread write to the log file. Create a single logger thread that takes lines from a queue and a method that lets other threads pass lines to be logged to it. (See my example here of using a BlockingQueue to create a logger thread.)

    Then, to know which thread wrote the line, write something like the thread name at the beginning of the line. When you create your threads, remember to set their name to something useful.

Similar Threads

  1. Replies: 7
    Last Post: 09-26-2011, 11:29 PM
  2. Writing to DAT or TXT file
    By hunterbdb in forum Advanced Java
    Replies: 7
    Last Post: 10-12-2008, 02:50 PM
  3. Replies: 9
    Last Post: 07-10-2008, 04:52 PM
  4. Replies: 0
    Last Post: 04-07-2008, 08:14 PM
  5. writing to a file
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 02:49 AM

Posting Permissions

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