Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:01:16+00:00 2026-05-27T02:01:16+00:00

I have a file. It sometimes happens that one thread has finsihed reading the

  • 0

I have a file. It sometimes happens that one thread has finsihed reading the file. The moment he is closing the reader another thread comes and try to read from the same stream associted with the reader. But then i get some

  stream already close exception.

How i can resolve such issues.

Like

new BufferedReader(new InputStreamReader(in));

How i can i create seprate stream for different threads.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:01:17+00:00Added an answer on May 27, 2026 at 2:01 am

    Well, in my opinion you should not close the stream when a thread has finished its work. Just leave it open and close it when all the work is done.

    Of course, since you are using the same stream you will need to synchronize access to the stream to prevent conflicts. You just need to use an object as a monitor. Like:

    synchronized(monitor) {
        monitor.wait();   // wait for signal
    }
    
    // read from input stream
    
    synchronized(monitor) {
        monitor.notify(); // release the next thread to start reading
    }
    

    Each thread will run this code. Then the main thread will call notify for the first thread to allow it to read and then if you start other threads they will wait for the previous one to finish.

    Note that here I’m assuming you don’t want to read from the file in parallel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service that sometimes calls a batch file. The batch file takes
I have one writer which creates and sometimes updates a file with some status
I have a small flash file that just loads and shows one image scaled
I have created a concurrent, recursive directory traversal and file processing program, which sometimes
Suppose that we have file like this: sometext11 sometext12 sometext13 sometext21 sometext22 sometext23 Texts
AS sometimes happens, I have created what I would say is a hot mess
I understand that minifying tries to reduce file size by removing whitespace characters. Sometimes
I have a simple script that should cause one of three divs to be
I have a UIView control in the nib file that I am working on.
I have a project that uses 3 other projects as libraries and has quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.