How to close other thread's InputStream?

Hi,
I am developing a multithreaded "JAVA CONSOLE APPLICATION".
Brief description of application is like this:
On initialising, application starts a new thread. In that it listens for the keyboard input from the user(System.in.read()). But it listens only for some time (5 seconds). After this time, this should be stopped and in main thread which is listening for the server application, should display information from the server and listen for the keyboard input from the user.
But the problem is, it listens for two keyboard inputs. 1 in main thread and another in other thread as it doesn't get closed even though the thread is stopped.
So how to close that InputStream so that application should listen for keyboard only in main thread?
Thanx in Advance,
Sameer Mahajan

Not really sure if this works, as your description isn't clear.
But for sockets, the following works :
public void run { //the Threads/Runnable run method
   try {
      //do your stuff
   } finally {
      try {
         is.close(); //supposed 'is' is your InputStream
      } catch (IOException e) {}
}Now, whenever the thread terminates, the InputStream will be closed.
Maybe even if you use Thread.stop(), but this is deprecated,
so better use Thread.interrupt() and flags.

Similar Messages

  • How to close other Windows Programs from a Swing GUI ?

    I am making this really simple login program that once a user has successfully entered a username and password, and this is checked through a mySQL database , I run an Internet Explorer Windows.
    Now I am trying to setup a logout button and when they push this button ideally the open Internet Exlporer Windows would close.
    Does anyone have an idea how to do this is Swing or the wider java language or maybe even something built into windows ?
    S.

    It's as simple as obtaining references to the Windows and calling dispose() on them. How you obtain the references is entirely up to you. For example, you can create a List to hold all the children windows/dialogs that are created. And on logout you iterate through the list, dispose the child windows, and remove them from the list. Or maybe the child windows can add themselves as listeners to the logout button. When it's clicked and an ActionEvent is fired, the child windows can dispose of themselves automatically.

  • How to Close Issue

    hi Experts..
      When i got the solution ..Please tell how to Close the Thread....
    Cheers..Purushottam

    Hi,
    You can either assign 10 points to the answer that solved your problem. Or if you found a solution yourself, you can click on the radio button for Solved by myself.
    Hope this helps...

  • How to find my threads?

    Hi:
    Can some one tell me how to find the threads/questions I opend here? I some time by luck can find all thread I created but other time cant, like today I cant? How to close a thread. Thanks.

    Hi,
    i find my content when i
    - click on my user name in the upper right corner after having logged in
    - on the screen opening next i navigate to tab "Activity" and here they are...
    Regards

  • SCN - How do I close the Thread of communication

    SCN - How do I close the Thread of communication
    Sanjay

    By changing the status of your discussion.
    from Not Answered to Answered or Assumed Answered.
    Also read the blog to know more How to close a discussion and why

  • How to close Thread

    HI,
    I  open previous thread and i don't get answer ,
    i wont to close it how i do that?
    Regards

    By searching this forum, I found the thread below which explains on how to close threads.
    https://forums.sdn.sap.com/click.jspa?searchID=16410079&messageID=5867611

  • How to make one thread to wait for others in this situation?

    i am simulating a 2 phase locking system (shared and exclusive locks). multiple clients connects and requests for lock to a single server. at the server end, we have a class Server which implements Runnable interface. for each connection, a new Server object is created and a new thread is started. when a conflicting lock request is made by a client, the corresponding thread in the server end must wait until other threads corresponding to clients holding the lock releases it. and when all the locks in conflicting mode are released, the thread releasing the last conflicting lock must notify the waiting thread.
    but the wait() and notifyAll() methods are not working as desired. i guess this is because each thread is working on different Server objects.
    how can i implement the waiting and notifying mechanism?

    Let me recap your question: your Server is a single resource to which
    multiple Clients want access in a CREW (Concurrent Read Exclusive Write)
    fashion. You need a single object somewhere that can serve as the
    single monitor for locking. A Singleton object like this should do it:public class CREW {
       private static CREW crew= new CREW();
       public static getCREW() { return crew; }
       private boolean wite;
       private int read;
       public synchronized acquireReadLock() {
          // your read locking stuff here
       public synchronized acquireWriteLock() {
          // your write locking stuff here
    }... the important part is that there is a single object to lock on. The
    'acquire...' methods can be pooped up at will (a Command as a
    parameter mayhap?)
    kind regards,
    Jos

  • How to reverse audio in logic pro X? Other thread didnt help

    Hello,
    i am trying desperatly to reverse a cymbal sound in Logic Pro X but i cannot find how to do it. Can somebody help me please
    I already activated the advanced options:
    i followed avery step i found in other threads but it doesnt work. (audio editor, functions and then reverse) i also didnt find the "reverse" button under "functions".
    Can somebody help me please? I am new to Logic..
    Sorry for my bad english, i writing this from Belgium
    Sincerly

    That's a little odd !! Not quite sure why that wouldn't work… You have assigned your sound to the output track rather than an audio track, but that shouldn't stop it working.
    On the other hand, I wouldn't have done it like that at all
    I would select the midi track to convert and do a "Bounce in place".
    With the default settings, Logic will create a new track with the bounce on it. You can manipulate this new bounce as you please
    Have fun

  • How to close Internet Explorer and other programs running on Windows?

    In order for Flash Player to be installed or updated, any programs that use Flash Player must be closed.  This includes Internet Explorer or other browsers, instant messengers, Skype, etc.
    These programs may be running in the background, not as visible windows, but need to be closed anyway.
    To close such programs use the Windows Task Manager.  To start Task Manager, take any of the following actions:
    Press CTRL+ALT+DELETE, and then click Task Manager.
    Press CTRL+SHIFT+ESC.
    Right-click an empty area of the taskbar, and then click Task Manager.
    Once the Task Manager is running, select the Processes tab.  On older Windows version you may need to click on the Process Name or Image Name header to sort the process names.
    Now right-click on every process that the Flash Player installer needs to close (e.g. iexplore.exe), then select End Process.
    It would be desirable if the Flash Player installer could perform that action by itself; I have therefore created an enhancement request.  If you were affected by this problem, please head over to the Bugbase and vote for this request: https://bugbase.adobe.com/index.cfm?event=bug&id=3548136

    See How to close Internet Explorer and other programs running on Windows?

  • Problem with Thread and InputStream

    Hi,
    I am having a problem with threads and InputStreams. I have a class which
    extends Thread. I have created and started four instances of this class. But
    only one instance finishes its' work. When I check the state of other three
    threads their state remains Runnable.
    What I want to do is to open four InputStreams which are running in four
    threads, which reads from the same url.
    This is what I have written in my thread class's run method,
    public void run()
         URL url = new URL("http://localhost/test/myFile.exe");
    URLConnection conn = url.openConnection();
    InputStream istream = conn.getInputStream();
    System.out.println("input stream taken");
    If I close the input stream at the end of the run method, then other threads
    also works fine. But I do not want to close it becuase I have to read data
    from it later.
    The file(myFile.exe) I am trying to read is about 35 MB in size.
    When I try to read a file which is about 10 KB all the threads work well.
    Plz teach me how to solve this problem.
    I am using JDK 1.5 and Win XP home edition.
    Thanks in advance,
    Chamal.

    I dunno if we should be doing such things as this code does, but it works fine for me. All threads get completed.
    public class ThreadURL implements Runnable
        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
        public void run()
            try
                URL url = new URL("http://localhost:7777/java/install/");
                URLConnection conn = url.openConnection();
                InputStream istream = conn.getInputStream();
                System.out.println("input stream taken by "+Thread.currentThread().getName());
                istream.close();
                System.out.println("input stream closed by "+Thread.currentThread().getName());
            catch (MalformedURLException e)
                System.out.println(e);
                //TODO Handle exception.
            catch (IOException e)
                System.out.println(e);
                //TODO Handle exception.
        public static void main(String[] args)
            ThreadURL u = new ThreadURL();
            Thread t = new Thread(u,"1");
            Thread t1 = new Thread(u,"2");
            Thread t2 = new Thread(u,"3");
            Thread t3 = new Thread(u,"4");
            t.start();
            t1.start();
            t2.start();
            t3.start();
    }And this is the o/p i got
    input stream taken by 2
    input stream closed by 2
    input stream taken by 4
    input stream closed by 4
    input stream taken by 3
    input stream closed by 3
    input stream taken by 1
    input stream closed by 1
    can u paste your whole code ?
    ram.

  • How to stop main thread ?

    Hi,
    Inside my java class, after I launch a GUI, I want to stop this main thread. After user make some choice and close GUI window, then, I want to go back to main thread. I use wait() method inside my class to stop main thread , but it does not work and it give me "IllegalMonitorStateException" error. I met same thing, when user close the GUI window and call method notifyAll(). How to stop main thread for a while and how to go back?? Thanks
    Gary

    Hi,
    you can create a boolean, and create a while loop, with a Thread.sleep(time); when you want to continue, you just have to change the state of your boolean. So you don't hava to exit the main. And you can't restart a run() in a thread. You can run it only once, so try to keep in your run() with an appropriate loop.
    Hope it helps.
    S�bastien

  • Here's my Vent of the Day - How about one topic/thread per subject?

    I see lots of topics/threads started that are exactly the same as ones already out there, and many of those could be answered if the OP would just search what's already been said, or read generally available information before posting. And then there are so many posts for which even the OP knows don't have an answer. It's just hard to wade through all these repetitive posts to find the ones that need answers or could be informative to all.
    _For instance, how about a single thread for some of these_?
    How do we get our free cases
    When will Apple make a hardware change to iP4
    Do you think I should buy now or wait
    I'm happy with my phone, why aren't you
    Let's all complain about Apple, Steve, whatever
    Now what was it that was said in the Press Release? (like maybe go read it)
    Face Proximity should be fixed
    Antenna Problem should be fixed
    So that's my vent for the day (everyone else is doing it). Come to think of it, I'm gonna change the topic of this post to "Here's my Vent of the Day"
    Message was edited by: DianeX
    Message was edited by: DianeX

    R C-R wrote:
    Keep in mind that a lot of new or occasional Discussions users are not familiar with how the Discussions search engine works & that it is, to be kind about it, more than a little quirky. For instance, even many regular users don't know that the default search box scope is different depending on the category you use it from. And compared to "smart" search engine technology like say Google or bing uses, you often need to use the arcane, 1990's era syntax mentioned in Search Tips to get good results.
    Plus, users not already familiar with an issue or its terminology often have no idea how to create a good search query that doesn't produce an overwhelming number of unrelated hits.
    Besides, venting & ranting are close cousins & the ToU make it clear these forms of self-indulgence are not really acceptable topics for Discussions to begin with. I'm sure a huge number of Discussions users are frustrated by all the topics taken over by such things, but {ahem} venting that frustration is just adding more fuel to the fire, so to speak.
    My point may have been more clear if I hadn't somehow posted this on the Discussions area instead of the iPhone4 one, where there are continual repeats of the same topics (most of which have no answer anyway)

  • "could not start the camera. Close other apps and try again"

    It shows up saying could not start the camera. Close other apps and try again when i try to open the camera but no other apps are open.
    how do i fix this?

    Hi.....i am new here and is not sure as yet how to start a new thread. 
    I have a bb curve 8310 and think i may ave caused my camera to stop working via uninstalling it....if that is possible. 
    wen i click on di camera it opens, makes shutter sound and flashes wen i click di trackball but after that it doesnt show di picture that it supposedlt took.
    Before this happened i was foolin around with the hide a folder option in pictures and not sure what i did wrong.......my video is not clear either.....please can you help me .....in addition i do not get any of those messages that i see the other users saying that they got for example could not start camera....i am not getting anything like that. all dat i get is a white screen......

  • How to close the COM Port ??????????

    Dear all :
    I have written an application that send AT commands to a modem , Once I opened a com port , i don't know how to close it . I got the null pointer exception when i create a new channel , because the inputStream and outputStream is owned by the previous channel . So , some one can teach me how to close the com port that opened before ?
    my source code for open port :
    public void Connect_Com(CommPortIdentifier portId) {
    Integer i = new Integer((int) (Math.random()* 1000));
    String channel = "channel" + i.toString();
    System.out.println(channel);
    try {
    System.out.println("preparing to open port");
    serialPort = (SerialPort) portId.open(channel, 2000);
    } catch (PortInUseException e) {}
    try {
    inputStream = serialPort.getInputStream();
    System.out.println("getting inputStream");
              } catch (IOException e) {}
    try {
    serialPort.addEventListener(this);
              } catch (TooManyListenersException e) {}
    serialPort.notifyOnDataAvailable(true);
    try {
    serialPort.setSerialPortParams(9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {}

    serialPort.close() ?
    From the documentation of SerialPort:
    - SerialPort extends CommPort.
    - CommPort.close() closes the communications port.

  • How to make the Thread as a Answered

    Dear Support Team,
    How to make  thread as a Answered one , Because  it still showing Not Answered.I want to change the status as a Answered.
    Re: Price Variance hitting PPV account even when there is stock.
    Thanks for our support.
    Regards,
    Thambi.

    You can close this thread by selecting whichever reply you feel is correct as CORRECT ANSWER. OR if you feel there is no proper reply to correct solution, you may also mark your query as Assumed answered.
    Did you not go through How to close a discussion and why
    Regards,
    Jitendra

Maybe you are looking for

  • How to restrict login from client?

    Hi all, 11gR2 How do I restrict login from client users, because I want to backup our database using expdp, and I do not want anybody updating the database. I can not use the startup restrict becuase some client have dba privs. I am thinking of shutt

  • Help with capturing VHS onto the FCP drive

    Hello, I'm a new (novice) G-5 FCP user and I'm trying to attempt to capture video through my VHS player (from the VHS Tape) and dub it into my new Panasonic PVGS31 mini dv camera, or if possible, bypass the dubbing to mini dv and capture the video st

  • Emailing scanned documents?

    After hooking up my computer and printer, I tried to scan a document and submit it for email which only prompted a message " no email program assocication  to perform.  Please install or create association in the default programs control panel."  Wha

  • USER DEFINED TABLES IN XL REPORTER

    Hello, I have a user defined field based on a user defined table with code and name. I call my user defined field in XL reporter. This field varied with the data that I report. I would like to know how I can add the name of the table in my XL report.

  • R/3 Query in BI

    Dear all, Can anyone tell me how to adopt the R/3 query created in SQ01 be adopted in BI as datasource and for further modelling. Regards, M.M