Timeout for  "new BufferedReader (new InputStreamReader (System.in));"

BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
String message = in.readLine();  The above code waits infinitely until the user enter the data from the command line and presses enter key.
The following code can provide a timeout to the above waiting (it works fine).
But is there a SIMPLER WAY to provide timeout for above waiting, something like setSoTimeout(int milliseconds) method in DatagramSocket, Socket and ServerSocket classes*?*
http://www.coderanch.com/t/232213/threads/java/implement-timeout-threads
=>
import java.util.Timer;  
import java.util.TimerTask;  
import java.io.*; 
public class test{  
private String str = "";  
     TimerTask task = new TimerTask(){  
             public void run(){  
          if( str.equals("") ){  
               System.out.println( "you input nothing. exit..." );  
               System.exit( 0 );  
     public void getInput() throws Exception{  
          Timer timer = new Timer();  
          timer.schedule( task, 10*1000 );  
          System.out.println( "Input a string within 10 seconds: " );  
          BufferedReader in = new BufferedReader(  
               new InputStreamReader( System.in ) );  
          str = in.readLine();  
          timer.cancel();  
          System.out.println( "you have entered: "+ str );   
     public static void main( String[] args ){  
          try{  
               (new test()).getInput();
          }catch( Exception e ){  
               System.out.println( e );  
          System.out.println( "main exit..." );  
}

No. System.in doesn't have a timeout API. Sockets do.

Similar Messages

  • Diff bet  args and using BufferedReader(new InputStreamReader(System.in))

    What is the differece between getting a string via args and using BufferedReader(new InputStreamReader(System.in))??????
    Please help me to know

    via argsI presume you mean the command line arguments? Well that'd be the command line arguments: ergo: "Hello World" would be the arguments in: java -cp . Say "Hello World"
    System.in is the standard input stream... The console (ie the keyboard) when a java program is run within a "standard" command line environment.
    Cheers. Keith.

  • Feedback for new Email system - do you like it, or...

    Does anyone know whether it is possible to give feedback  on the new email system to anyone in BT who might listen (and preferably do something about it)?
    I am finding it much slower that the previous version; I don't like the pop up messages - email sent - do you really want to log out, etc; I don't like the fact that it times out constantly, even in the middle of an email.  I don't like the fact that it's greyed out every time you log back on, so you have to make the same decision about cookies half a dozen times every day - after telling it N times that I wanted "functional" only, I've now given up - it changes back every single time to the default system - so what's the point in asking.
    I've been using email for a good few years now, other systems as well as BT, and have not come across anything that is quite so annoying, difficult to operate and generally "nannyish"
    Is it just me, or is anyone else finding it a bitter pill to swallow?  Someone on the Forum suggested I use Thunderbird, but having looked into it, it seems to have very mixed reviews.  The only good thing about BT is the anti-virus software - would that still work if I went through another system?

    Hi AnneH,
    Umpire here from the other thread.
    I see you still haven't taken the plunge and tried an e-mail program. Not sure about mixed reviews of Thunderbird (are you sure they were recent reviews as it has been around for many years). I have used lots of different e-mail programs over the years and currently use Thunderbird on my home PC. Anyway, you can use any e-mail program you want to. Windows Live Mail will do the same job, as will many others.
    The reason why most people recommend either Thunderbird or Windows Live Mail is just because they are the ones in very common use. They are from the same people (Mozilla and Microsoft) that also provide the commonly used Firefox and Internet Explorer web browsers respectively.
    You really need not worry about the security. In fact I would say that an e-mail program is always going to be a more secure way of accessing your e-mail accounts. A large proportion of computer malware is aimed at web browsers. Webmail is always going to be obvious target for those trying to steal your personal info. The virus checking that BT do on their mail servers will still be taking place in exactly the same way if you use an e-mail program. You will also still find things moved to the Spam folder by BT.
    The commonly used PC security software packages will also fully integrate with the common e-mail programs and check messages for viruses in the background. E-mail programs often also offer additional spam checking services (in addition to the BT spam checks) which you can turn on/off should you wish to. Personally I find the BT checks sufficient and keep things simple. 
    Ask yourself this. If an e-mail program offered a lower, riskier level of security then why would so many people with more technical knowledge/experience use them? Also why would most large companies and corporations use them?
    I appreciate that what you would like is for BT to drastically improve the webmail interface and allow you to just carry on using that stress free, but is that really likely to happen in the near future?

  • Activating transfer rules for new source system

    Hi
    we are having 2 R/3 source system in BI. I had activated all the transfer rules with the first source system and now i have created a new source sytem connecting to a different R/3 client. I tried to change the transfer rules point to the new source system using the program RS_TRANSTRU_ACTIVATE_ALL giving the new source system and the infosource name. But i get the error "No Transfer Structure Selected" when i execute the prg.
    how can i change the source system without creating the transfer rules for the new source but use the existing transfer rules and just change the source system assigned to it????
    Regards
    Sujai

    Hi Sujai,
    There are many cases when this program is used.
    When the Trans rules get de-activated due to impact,we need to first replicate the data source and activate the TR using this program.This generally occurs during the data loads in prd.
    It does not makes sense to transport it when there r no changes done to the TR.So simply,u can use this program to activate.
    If the program does not work,then you are left with the transport option.
    Thanks & Regards,
    Suchitra.V

  • Hard Drives and video card for new CS5 system

    I've read through much of the threads in the hardware forums and find I still have questions.  I am just beginning to learn how to edit and it is not a source of income for me at the moment.  My sources will be from tapes from my Canon HV20 and at some point either a Panasonic GH2, Canon 60D or similar.
    I have bought the following:
    ASUS P6X58D-E motherboard
    24 GB of Patriot Sector 7 DDR3 1333MHz memory (9-9-9-24)
    Intel i7-950 3.06 GHz CPU
    I plan to use Cineform NEO or maybe NEO HD to ingest my files.
    I also have 4 Seagate 750GB 7200.11 hard drives I can use.
    It seems like the best bang for the buck for a video card is a GTS 450 at about $100 because I can't find any data that indicates a GTX 460 or a GTX 570 would make any difference (see http://www.studio1productions.com/Articles/PremiereCS5.htm)
    As far as hard drives goes, Harm's article on creating separate storage makes sense to me.  It seems like I could create a "4 drive" system quite easily (see http://forums.adobe.com/thread/662972).  Given that I am not ready to spend moeny on an Areca card until I can develop my skills,  I am wondering if I should get one of the new WD Velociraptor 600GB (SATA 6) drives as my system drive for about $280, a 150 GB (SATA 3) Velociraptor drive for about $100, or some other fast drive.
    Given that my motherboard can support RAID, should I consider RAIDing the "D" drive or the "E and F" drives?
    Is there any value to using an SSD drive for the "E" drive (page file and media cache) [see http://forums.adobe.com/thread/662972]?  Microcenter has a 64GB drive for $100.
    Thanks in advance.

    Hi Harm,
    First let me say, I didn't mean to exclude Bill Gehrke.  I just didn't know what was what.  Thank you for explaining that to me.  Let me also say the you and Bill have a great site.
    I have a question for you,  in the tests I have run with my systems, I am not seeing any speed difference between the 450 and 480.  Now granted, they are AMD processors and I know they don't have the SSE 4.1+. Here are my systems that I ran the tests on:
    An AMD X4 Quad Core computer running at 2.9 Ghz with 12 gigs of RAM and a single Samsung 7200 rpm SATA 3.0Gb/s hard drive
    An AMD X6 Six Core computer running at 3.2 Ghz with 12 gigs of RAM and a single Samsung 7200 rpm SATA 3.0Gb/s hard drive
    Both computers were running the same version of the NVidia driver and all non-essential programs were disabled.
    When I test the 450 and the 480 in the AMD X4 system, they are turning in pretty much the same level of performance, in that system.
    The same holds true with the AMD X6, the 450 and 480 turn in virtually the same level of performance, in this system.
    The AMD X6 with either the 450 or 480 does turn in a better performance over the AMD X4 with either video card.
    The question.... Are you seeing result that are like this?  Where using the exact same computer, turns in the same results with different video cards.
    From the number of emails I get about the article, other have reported this to me also.  I have had a few people who said when they did see a minor speed increase when they did switch between a 450 and a 480 and a couple who did see a good speed increase.
    I am working on changing the article to reflect this and would really appreciate your input or Bills input on this. 
    I have looked at your benchmark chart and read through the result, but one thing that concerns me when reading some of the results is what programs do they have running in background, if any.  And how is that effecting their performance.  That is why I used the two systems I listed above to do the tests with.  It gives me a controlled enviroment to do test the performance of the video cards in.
    As a side note, when I tested the 450 and 480 cards in a friends Intel I7 system, again we didn't see any performance difference between the two video cards, but he did have some programs running in background which may have caused the perfornce results I got.
    Best Regards
    David Knarr

  • Suggestions for new stable system?

    So I am looking at getting the MSI Neo2-FIS2R, and have been reading through all the problems people are posting on this forum.
    I am not looking at doing any real overclocking just yet (I am fairly sure overclocking my old P2 eventually fried the board), but if things work out right, then maybe I'll look into it in the future.
    I was planning the following system:
    MSI Neo2-FIS2R
    Pentium 4 3.0C 800FSB
    1GB PC3200 Kingston mem kit (3-3-3)
    Seagate 80GB SATA (plus an old 40GB IDE)
    Sapphire ATI Radeon 9600 Pro Atlantis
    XP Home
    Antec True 380W PSU & case
    Should this be a stable system with good performance with this motherboard? Do I really need to go for better memory (Geil 1GB PC3500 kit and Corsair Twinx 3200 kits are options)?
    Thanks.

    The numbers used by that program to determine the watts required are valid. You will get similar totals doing the exercise by hand.
    I don't know if anyone is making a large power supply that is not switch mode, but in either case efficiency is irrelevant in supplying power to the computer. It wants a certaing number of amps at a certain voltage, which will give you watts. If you need 400W you can use a big old iron power supply with 50% efficiency so that the computer gets 400W and the cooling air gets 400W, or you can get a switch mode supply with 70% efficiency that gives the computer 400W and the cooling air 170W.
    In either case the power supply watts rating is at the output, not at the input.
    The power supply rocks009 is looking at is marginal for his current configuration. I would expect that he has one or two optical drives not included here, maybe a few USB devices.
    This place  shows a price difference between the 380 and 480 of about $31 CDN, and the 550 of $48. CDN $ usually get divided by a big number when converting to another currency so the cost is marginal.
    You may be right jaeger66, but I'll put up my electrical engineering degree against yours )

  • Basic Customizing for new SCM system

    Hello,
    we are implementing a brandnew SCM 5.0 system. Does one of you know where I can find a checklist what steps should be done as "basic" setup?
    I'm talking about things like:
    - setup RFC destinations
    - define logical systems
    - Create model 000
    - Create planning version 000
    Thanks and Regards
    Stefan

    It depends on which are the SAP Modules-Functionality you are implementing
    In your list you can add
    -- CIF related to settings
    -- Live Cache settings done properly or not (Basis Team)
    -- SAP Standard Planning area/Infoobjects are present in the system or not
    -- Planning Object structures are active or not
    -- Consistency check to be done for Live Cache, DB, Time seris etc
    Rest in more details you can get from the link
    http://help.sap.com/bp_scmv150/BBLibrary/HTML/BBLibrary_EN_DE.htm

  • Timeout for readline

    Dear all,
    When reading some data from an input stream e.g. readline(), it is waiting for incoming data. Is it possible to set a timeout that make reading abort after a certain time?
    I know how to use timers but I'm not familiar with any aborting procedures for readLine()
    Thanks for any help in advance,
    Ron

    import java.io.*;
    * @author  Ian Schneider
    public class HowFastAreYou implements Runnable {
        public void run() {
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("you typed " + in.readLine());
            } catch (IOException ioe) {
                ioe.printStackTrace();
        public static final void main(String[] args) throws Exception {
            Thread t = new Thread(new HowFastAreYou());
            t.start();
            Thread.sleep(1000);
            t.interrupt();
            System.out.println("too late buddy");
    }Threads tutorial - there are two threads used in this example. The first thread is spawned by the jvm itself when main is invoked. This thread spawns the input thread. InputStreams are usually blocking (synchronous) , that is, the current thread will no return from a read call until data is present (versus nio, which provides support for an asynchronous API). So the spawned thread is waiting for input, but the main thread carries on, where it then sleeps for one second. If you haven't pressed return by then, the main thread "interrupts" the input thread. This means the blocking operation ends.

  • Can I use my new iphone 5 with the old iHome iD9SVC Speaker System if I get an apadter? or should i just buy new speaker system made specifically for the iphone5

    can I use my new iphone 5 with my old iHome iD9SVC speaker system if I get an adapter? or should i just buy a new speaker system made specifically for the iphone 5?

    Look iTunes>Preferences>Devices...is a backup listed for your iPhone 5 dated BEFORE you restored your iPhone 4 backup to your iPhone 5? If not, your data is gone. If there is a backup, on your iPhone 5: Settings>General>Reset>Erase All Content & Settings. You should now be able to restore that backup, if it exists, to your iPhone 5.

  • I have the Mac Os 10.4.11, and iTunes store will no longer come up on my screen to order tunes.  A download screen appears for the new iTunes. I can't download the new iTunes unless I get the new operating system for my mac.  Is there a way around this?

    I have an iMac with a 10.4.11 operating system.  When I click on iTunes Store, I no longer get the iTunes screen, instead, I get a new iTunes download screen.
    I can't download the new iTunes without upgrading my operating system.  Is there a way around this problem without buying the new operating system?
    I haven't been able to download songs for awhile now.

    which version of iTunes are you on ? if it's earlier than iTunes 9.2.1, get it here.

  • When we try to use apple tv there is no sound.  It was working fine for over a year.  Stopped working after we installed a new wifi system in the house - any suggestions?

    It was working fine for over a year.  We installed a new wifi system - could that have anything to do with it?  It connects fine but will not play any sound?  Any suggestions

    Thank you...I did try that and it did not work.  I've tried just about everything.  Today I tried hooking up to a different TV that does not have a receiver and it works fine.  I guess it has something to do with my receiver but I just can't figure it out.

  • New Logical System for every BPM in R3?

    Do I need to set up a new Logical System in my R3 system for every BPM in XI that sends IDOC to it?
    I need several BPM to split messages which I want to send to a R3 system. When I configure the scenario, the BMP is imported to the Configurator and the Adapter-Specific Identifiers need be added. A Logical System must be entered for the IDOC adapter. This Logcial System must be unique.
    Is it possible to have several BPM without setting up a logical system in R3 for each of them?

    Hi Elling,
    You can overwrite the logical system name in the receiver agreement. If you select a different system (from the SLD) as Sender Service, the IDOC will be send using the logical system name of this sender service.
    What we normally do is, set the sender service for a BPM to the original sender service.
    Regards,
    Christiaan Schaake

  • Feasibility for a new production system in the same environment

    Dear friends,
    Our management has come up with a requirement of expansion of SAP environment to cover up users in a different country for their francise over there. The options we are considering are below:
    1. Implementing a whole new setup ( ECC, EP,BI, PI,Trex).
    2. Expanding the lease lines between the sites in both the countries and providing access to the present setup itself with enhancement in the current hardware configuration.
    or is it a good practice to keep a new Production system in the other country and add a new delivery route for the new production system within the current transport route ? How the license part may be taken care in these cases ?
    Your suggestions are welcomed.
    Many thanks,
    SUJIT

    Hi Sujit,
    The answer to this question really depends on whether the new country is going to share much of the same configuration with some tailoring to local laws and requirements.  If the system is going to be the same, then there is now reason to deploy a new system unless you are reaching technical limits for hardware.  For ease of management and usage, then having one system is preferred.  You can then upgrade your network to cope with the increased load and hardware as required. 
    Hope this helps,
    Graham

  • Can we create new partner types for quallity notifications in SAP system?

    Can we create new partner types for quallity notifications in SAP system?
    The business requirement is to limit the available entries for partners  displayed when they search in quality notification. I have already created new partner functions & assigned the relevant partner types, however struggling with defining new partner types.
    Would appreciate help in resolving this.
    Thanks,
    Nilesh

    I know this customisation setting ...It allows us to create the partner functions & assign it to the partner determination procedure.
    Then you can assign the procedure to the notification type.
    This customisation setting does not solve the problem I have.
    I'm looking for the partner type creation process which we assign to the partner function.
    Edited by: NILESH BHAVE on Aug 12, 2010 3:06 PM

  • I work in a High School and I am looking for a new library system that runs on the mac and is not windows based, can anyone recommend anything?

    I work in a High School and I am looking for a new library system that runs on the mac and is not windows based, can anyone recommend anything?

    That's a very broad question and difficult to answer without knowing more about you requirements.
    Try starting on this page Category review: library management software for the Mac |Part I  and part II  to get a starting point.
    regards

Maybe you are looking for

  • T500 and Windows 7.

    I have upgraded my T500 from Vista to Windows 7 ( 32 bit ) and everything went Ok but 2 issues : 1- I tried to instal Rescue and Recovery for Windows 7 ( 32 bit ) but it keeps showing an error message that there is a ( .tvt ) file missing . 2- I'm st

  • I can't open bookmarks from the menu in new tab on firefox 6.0 using the mouse middle button or right click. Is this normal?

    I can't open my bookmarks from the menu in a new tab. I'm wondering if this is simply not a feature and requires an add-on. I'd rather not need to use an add-on. can anybody help?

  • My Serial number doesn't work. What should I do?

    I just installed the Adobe CS4 Master Collection on my new laptop. All of the Adobe applications work perfectly fine except for Photoshop. It tells me that my serial number was already used twice. What should I do? It is letting me do a 30 day trial.

  • Turning off Grey date and event title window..

    When I scroll in IPHOTO 8 a nice grey little window appears saying what date the photos are from, and the event titles...problem is, when I stop it's still there. How do I turn it off? I tried clicking on it and in the window, but it's still there...

  • New To Java Coding, Help NEEDED With a little script

    Well im just working on a script with an open uni course im doing, ive dont the script i was asked to do, but i was wondering if i could expand it abit more * The DaylesGod class implements an application that * simply prints "Dayles God!" to standar