The Blocking IO Problem

I would like my InputStream read operations to timeout iff they've been blocking for so long. How can I do this?
In other words, one thread is executing a read statement on an InputStream, and another thread notices that the previous thread is stalled. How can that second Thread notify the first to stop the read operation and continue on?
Non-blocking IO in 1.4 would be nice, but my clients won't have that installed. I'm using the URL class, opening a connection, and then getting the InputStream to do reads currently.
One (flawed) solution is to simply disconnect my producer (reads from the socket) and the consumer (writes to the disk) and let the blocked thread just sit there. However, the program could be used for a long period of time, and I don't like the idea of having a possible 500 blocked threads lying around.
Any and all help/information is appreciated!
NAS

java.net.Socket
java.net.DatagramSocket
java.net.ServerSocket
This method allows you to specify a maximum timeout length, in milliseconds, that the following network operations will block:
ServerSocket.accept()
SocketInputStream.read()
DatagramSocket.receive()
Whenever one of these methods is called, the clock starts ticking. If the operation is not blocked, it will reset and only restart once one of these methods is called again; as a result, no timeout can ever occur unless you perform a network I/O operation. The following example shows just how easy it can be to handle timeouts, without resorting to multiple threads of execution:
// Create a datagram socket on port
//2000 to listen for incoming UDP packets
DatagramSocket dgramSocket =
new DatagramSocket ( 2000 );
// Disable blocking I/O operations,
//by specifying a five second timeout
dgramSocket.setSoTimeout ( 5000 );
The following code shows how to handle a timeout operation when reading from a TCP socket:
// Set the socket timeout for ten seconds
connection.setSoTimeout (10000);
try
// Create a DataInputStream for
//reading from socket
DataInputStream din = new DataInputStream (
connection.getInputStream());
// Read data until end of data
for (;;)
String line = din.readLine();
if (line != null)
System.out.println (line);
else
break;
// Exception thrown when network timeout occurs
catch (InterruptedIOException iioe)
System.err.println (
"Remote host timed out during read operation");
// Exception thrown when general
//network I/O error occurs
catch (IOException ioe)
System.err.println ("Network I/O error -
     " + ioe);
With only a few extra lines of code for a try {} catch block, it's extremely easy to catch network timeouts.
A thread can then respond to the situation without stalling itself.
The following code shows the polling mechanism and error-handling code.
for (;;)
// Check to see if a connection is established
if (st.isConnected())
// Yes ... assign to sock variable,
//and break out of loop
sock = st.getSocket();
break;
else
// Check to see if an error occurred
if (st.isError())
// No connection could be established
throw (st.getException());
try
// Sleep for a short period of time
Thread.sleep ( POLL_DELAY );
catch (InterruptedException ie) {}
// Increment timer
timer += POLL_DELAY;
// Check to see if time limit exceeded
if (timer > delay)
// Can't connect to server
throw new InterruptedIOException
("Could not connect for " + delay +
          " milliseconds");
While the connection is regularly polled, the second thread attempts to create a new instance of java.net.Socket. Accessor methods are provided to determine the state of the connection, as well as to get the final socket connection. The SocketThread.isConnected() method returns a boolean value to indicate whether a connection has been established, and the SocketThread.getSocket() method returns a Socket. Similar methods are provided to determine if an error has occurred, and to access the exception that was caught.

Similar Messages

  • How to Release the blocked Sales orders?

    Hi Gurus,
      Requirement: To Release the Blocked Salesorders
      problem: find out  any Tables  and procedure  to release blocked SO(allow to creating delivery for SO).
    how to Customer CreditLimit  and  Tables  of Theses...............
    Thanks in Advance..
    sivakumar.kasa

    Hi..
    AS per i knew......
    how to know cutomer CreditLimit?
    FD32,FD33...tcodes
    how to release blocked Sales order?
    VKM3
    Wait for some other views

  • Problem in navigating out of the block

    Hi,
    There is a form created with the help of data block wizard. The form contains 4 data blocks. The entry is to be done in a way that the first threee fields are from the first data bolck and the 4th field is from the next data block. The problem I am facing is that when i try to navigate from the first block to the 2nd block the WHEN-VALIDATE-ITEM trigger of the 4th item of the first block is getting fired, thus preventing me to move to the next block and there are no validation trigger on the block level.
    please let me know what the problem can be.
    Help is required urgently

    Hi,
    that's standard behaviour. Item Validation will fire when you change blocks. If validation is successful it shuld not stop you, also you could try using ITEM_IS_VALID which if fiddley way to do it.
    If it is possible for you to create a view that combines the columns the two blocks then it would make your data entry easier.
    one other option is to fiddle with the validation scope
    Easo

  • Blocks in the \dll folder problems

    Hello
    Below is a problem that we had crop up on 3 machines.  We are
    running some labs that reside on a server.  The labs are in
    "I:\Infinity_Labs" and the required DLLs are in "I:\DLL".  All of
    the systems run fine except for these three.  Below is the
    description of the problem and what we've tried to fix them, including
    the results.  Any help would be appreciated.
    >> 123NH -
    >> Systems #5, 10, and 16 (same numbering scheme as rm 124NH) are not finding
    >> the DLL directory for the labs. Examples of this are Week 1, Binary and
    >> Week 2, Digital. If you point them to the correct folder (i:\DLL), the
    >> labs run fine. Possible fixes: rerun the command line script for the
    >> previous error or reinstall software.
    >
    > The problem here seems to be that the blocks contained in I:\DLL are not
    > registered in VAB. The other systems seem to be picking them up fine on
    > their own automatically. These three are not. I tried manually doing so but
    > ran into the 'exceeding allowed blocks' error you were talking about finding
    > (but that we couldn't relocate later) before I could register them all.
    > Rerunning the command you gave us made no difference. Looks like we need
    > some more tech support.
    Please help.  Thanks

    I would recommend that you use VAB's Auto Build Menu... command to rescan all of the block components from any folders that contain the DLL files. The default folders are c:\Program Files\Hyperception\VABINF and c:\Program Files\Hyperception\VABINF\Hierarchy. You will need to select the 'Delete existing libraries' option. VAB has a maximum limit on the number of block components that can be supported. If the Auto Build Menu... command does not correct the problem then it may be possible that too many user-created, custom blocks have been added to the VAB Block Function Selector. Regards, Steve

  • I am having problems with NI-FBUS configurat​or hanging when I try to view the parameters by double clicking on the block

    I am having problems with NI-FBUS configurator.  When I double click the function block to expand the block and view parameters the configurator will hang and eventual issue a "Fieldbus Configuration Application has Stopped Working" error.  I can use dialog and see each parameter with the "getobject" command just fine.  I have uninstalled the package and reinstalled it with no change.  I am operating Windows 7 with configurator version 4.1.0.49152  Comm manager ver 4.1 with the USB interface adaptor.
    Any ideas would be appreciated.

    Hi
    This might be a bug fixed in version 4.1.1, which is free for you since your version is 4.1.0. 
    Please try to upgrade it here

  • How can I open a vi and show the block diagram?

    Hi,
    I am opening an vi using "Open VI Reference" and "Invoke Methodpen FP", but I want to open the vi and show the block diagram, but I haven´t found any method (Invoke Method) to do that and any property.
    Any idea?
    Thanks!
    Gracinda

    OK, I can come up with a reason.  I have written a program that will search the entire VI Hierarchy of a program and update all of the descriptions for all VIs with the top level program part #, the name of the top level program that the VI is used in, the company copyright info, the ITAR notice, company address, the name of the engineer performing the update, along with the date and time.  This will also place as a background image on all the VIs, a watermark of the company name, legality stuff and the copyright. It works very slick in that if there are thousands of sub-vis, such as what I'm working on now, it goes through all of them, makes sure the data is there as per company policy without having to open every one of them look at them and update or not whichever the case may be. The one portion that is tough is that the program will detect if there is a description written about what funtion the VI performs and if there is not a description, then it pops up a dialog requesting the user to write a description. The problem is that without looking at the block diagram for the VI, it can be nearly impossible to write a description for the functionality of the VI. So is there a way to programmatically open a VI, show its block diagram (this would only be in the case of a missing description) and then upon completion of the updates, close the block diagram? (I already open and close the VI programmatically in order to read the VI DESC and update as needed, but that is in the background and of course you can't see the block diagram).
    Thanks,
    Dan

  • How can I remove the blocked contacts from skype h...

    Peace be upon you
    How can I remove the blocked contacts from skype home and all skype features?

    I found this solution and it worked.
    Paul B. Adams
    Re: safari 6.0 flash problem (blocked plug in) 
    Jul 26, 2012 7:39 AM (in response to defconnect5)
    I have a new MacBook Pro and I followed these instructions, downlonading and installing the new Flash plugin. But when I looked in "/Library/Internet Plugins" there was no folder called "Disabled Plugins".
    However, I did see two versions of Flash:
    _Flash Player.plugin with old date
    Flash Player.plugin with todays date
    I deleted _Flash Player.plugin and this fixed the problem.

  • Using a variable outside of the block it has been incremented

    Hello everyone,
    I came across a scenario where in I am having to use a variable (for summing up), outside of the block within which it has been incremented. Its something like below:
    -------------- Header section of MS Word RTF (repeats for every page) -----------------------
    For Each Header
    <?xdoxslt:set_variable($_XDOCTX, 'TotalTax', 0)?>
    -------------- Body section of MS Word RTF -----------------------
    <?start:body?>
    Lines Group
    Increment TotalTax for each loop
    End Lines Group
    <?end body?>
    -------------- Footer section of MS Word RTF (repeats for every page)-----------------------
    <?xdoxslt:get_variable($_XDOCTX, 'TotalTax')?>
    End For Each Group
    ---------------------------- End of template ----------------------------
    The varaible 'TotalTax' is being declared in the header, incremented within the Body and is being used in the footer section. For the above mentioned syntax, the value being displayed for TotalTax is '0', i.e the value for which it has been defaulted while declaration.
    Can someone please help me in getting it fixed such that TotalTax would display the value it was assigned in the Body rather than '0'.
    Thanks,

    Hello and thank you for responding.  I checked out the link you provided; however, my problem is not reviwed there.
    I am setting a variable inside a <?start:body?>.  Inside the body are several loops - which is fine.  But it ends with <?end body?>.  If I reference my variable BEFORE <?end body?> it retains it's value from the calculations within the program.  But if I try to use the variable AFTER the <?end body?>, it give me an error "NULL" value or similar.
    Any thoughts?
    Rob

  • Firefox 34.05 says plugin is out-of-date, insecure, and thus disabled. But...my version is higher than the blocked version

    Upon updating to Firefox 34.05, I've been faced with the fact that this version of Firefox (erroneously) thinks some of my plugins are out of date, and has disabled them, for my safety.
    For instance, it tells me that "Adobe Acrobat Reader is known to be vulnerable and must be updated". Upon clicking the link to update it, it informs me that "Adobe Reader 9.5.1 and lower has been blocked for your protection.". Okay, cool right? An update should solve that.
    Problem is, I don't *have* a version of AR that is 9.5.1 or lower. My version is, according to Firefox itself, version 10.1.4.38. So why is it blocked? Updating the version, as advised in other threads on similar issues, does not seem to work. In fact, the Mozilla plugincheck tells me that my version is up-to-date and is fine.
    It is very inconvenient to have to open an entirely different browser, like Opera, just to do certain things that I could previously do with Firefox.
    I'd also like to voice my overall disapproval on the way many features of Firefox (enabling disabling Javascript, images, certain stylistic features, the add-on bar) have been done away with and users are being told "you can install an add-on to add that functionality back on". It has always been my understanding that the less add-ons installed the better, given that they are apparently the number one problem when it comes to Firefox having issues. Having to disable 5 new add-ons anytime I want to troubleshoot a problem is not convenient, and makes locating the source of various problems more difficult.
    I have no idea why Mozilla is so committed to making changes that users hate, and act as if having third-party add-ons to restore functionality is any kind of solution.

    ''James [[#answer-672408|said]]''
    <blockquote>
    Firefox 34.0.5 is not doing the blocking as it is due to the blocklist. https://addons.mozilla.org/firefox/blocked/
    Adobe Reader '''10.0 to 10.1.5.*''' has been blocked for your protection.
    https://addons.mozilla.org/firefox/blocked/p158 (Blocked on October 5, 2012)
    You were looking at another blocklist page which was https://addons.mozilla.org/firefox/blocked/p156 posted on same day.
    The https://www.mozilla.org/plugincheck/ is not always accurate or reliable (needs to be manually updated) as Adobe has not been keeping the Adobe products versions to check for updated on that page as the recent Flash updates on December 9 has shown.
    It is however accurate when it says versions in Plugins panel of Addons Manager is outdated.
    There is Adobe Reader 11.0.10 though it seems like Adobe still provides 10.1.4 at http://get.adobe.com/reader/otherversions/ yet newer versions are at http://www.adobe.com/support/downloads/product.jsp?product=10&platform=Windows
    </blockquote>
    James, why does the Firefox addon page link to the 9.5 "blocked for your protection" page instead of the 10.5 blocked page? Is that a mistake/failure to update on Adobe's part? That seems like something that should be controlled on the Mozilla side, since it has the 10.5 blocked page in existence as well. Should someone be notified that it's giving the wrong page to people?
    The adobe update you linked to made it stop saying it's out of date, but what about the Java Development Toolkit? (As pictured in attached image #3). How should I go about getting that up to date?

  • Is it possible to block a number in iOS 6 but the same iphone number could be viewed as online on whatsapp application in the blocked device?

    Is it possible to block a number in iOS 6 but the same iphone number could be viewed as online on whatsapp application in the blocked device?

    Hi ChrisJ4203,
    I see you didn't comment on editing the numbers in the keypad, I believe you have that problem too but you forgot to click "I have this question too".
    By the way I've sent a couple feedback messages to Apple already and thanks for reminding me, I guess I'll have to be doing that more often.
    Enjoy your day

  • How can I interrupt the blocking call when call timeout?

    Hi,Guys
    I wrote an application server(daemon process) to talk with oracle server
    continuous which used oracle9 OCCI lib, each 5 min it executes the procedure
    on the DB server.
    Now I have come cross a problem:
    If the network is blocked, app server will blocked at occi call and would
    never pass, and no exception was catched :-(
    for e.g.
    1. Oracle server reboot without shutdown oracle process
    2. udp broadcast message storm blocked the connection between app server and
    oracle DB.
    I consider maybe it's because OCCI using the blocking mode of connection
    that caused this problem.
    How can I interrupt the blocking call when call timeout?

    Manage the timeout using a separate thread. When the timeout happens, issue a break on the OCCI connection. There is no direct way as of now. You need to do this to break a OCCI connection.
    retrieve the OCI handle from the OCCI handle (e.g. using Connection::getOCIServer or Connection::getOCIServiceContext methods) and issue a OCIBreak on it. Do not forget to allocate a error handle which should be passed to OCIBreak call.

  • Cannot place custom subVI on the block diagram

    When I press the "Select a VI..." button on the function palette and select the VI I want to place on the block diagram nothing happens. This only seems to be happening for two particular VIs. Most of the time I can place the custom subVI without any problems.
    Is there some option that could have accidentally gotten set that does not allow a VI to be placed on another VIs block diagram?
    Please let me know if there is any way to fix this problem.
    Thank you,
    David R. Asher

    David,
    What you sent me has a .ctl file extension. The ctl extension is for LabVIEW custom Controls, not VIs. Even though it is actually a VI, the wrong extension must be confusing LabVIEW and not letting it load. It's probably trying to put it on the front panel since that is where controls go.
    If you change the ctl extension to vi, it works as it should.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • The document Address doesn't show the block when country isn't USA

    hello
    i have a little problem, when I create a new document for a customer which ship to address's country is different from USA, the document Address doesn't  show the block. i checked the bp address in the bp master data and the block is written, also when i click on the ... button near the ship or bill to address the block has a value !! but when i go back to the document, there is an empty space where the block has to be in the document address.
    is there any configuration to solve this problem
    thanks a lot!

    Hi,
    The configuration is under Admin-Setup-BP-Address Format. Each country has a built-in format for address initially.
    Thanks,
    Gordon

  • How do I disable the blocking mode so I can use the apps I want to install.

    I want to disable permanantly this stupid blocking firefox does when I want to install or upgrade an app, particularly Java. It is my decision what goes on my computer not firefox. I was going to go to another browser when a person from firefox on facebook said I could disable it but didnt tell me how. So I want to know how to so I can disable it for good or I shall have to find another browser. Security or not its my choice what I put on my computer and I wont be dictated to about what I can or cannot have on my computer.

    hello Jenna9, i'm not aware that there is any blocking built-into firefox when you're updating java (quite on the opposite, users are encouraged to keep their plugins up to date). could you provide the exact wording of the blocking notification that you are seeing or provide a [[How do I create a screenshot of my problem?|screenshot]]?

  • Looking for the block CD Generate Time Profiles for MPC simulation.vi

    Hello everyone!!! I am trying to implement MPC in LabVIEW. I have downloaded certain codes which shows the implementation. My question is in those codes i see a block named as CD Generate Time Profiles for MPC simulation.vi. I tried finding a lot for that block but i could not... Can anyone help me out with the problem (exactly under which section will i get that block) or can anyone tell me how do i give the set point profile for the MPC simulation problem???
    Solved!
    Go to Solution.

    The VIs related to generate profile can be found in:
    C:\Program Files (x86)\National Instruments\LabVIEW 2011\vi.lib\addons\Control Design\_MPC\Reference Profile
    or
    C:\Program Files\National Instruments\LabVIEW 2011\\vi.lib\addons\Control Design\_MPC\Reference Profile
    You can look at examples in:
    C:\Program Files (x86)\National Instruments\LabVIEW 2011\examples\Control and Simulation\Control Design\MPC
    C:\Program Files\National Instruments\LabVIEW 2011\examples\Control and Simulation\Control Design\MPC
    to verify how to use those VIs.
    Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

Maybe you are looking for

  • Content Search Web Part Error / Control_list.js not found

    Hello, I am trying to use the Content Search Web Part but I receive an error: Display Error: The display template had an error. You can correct it by fixin the template or by changing the display template used in either the Web Part properties or Res

  • How do I delete a User that does not appear in Users & Groups?

    A leftover user (former employee account) that won't go away. Phantom User account becomes the default login account regardless of the new employee's login attempts. The phantom account Home folder appears in the Users folder at the root level, but n

  • Logon methods in user mapping

    Hi friends,    In user mapping we use any of the three logon methods which are nothing but authentication methods.can anybody please explain what are these methods? with regards sireesha

  • Remove un-neccessary dimensions from user POV

    All - There are total 8 dimensions which are part of user POV in my Financial Report. I would like to hide 2 dimensions (those will be set to "None" always) from user POV. I don't want to move those dimensions in pages/columns/rows and hide them. Is

  • DVI connection to Lenovo 6622-HB1 isn't working with Windows 7. Any suggestions please?

    I have a W510 in a 4338 Mini Dock Plus Series 3 running Windows 7. Previously I had a T60 in its docking station (2504) connected to a Lenovo 6622 (1680 by 1050) connected using the DVI connection which worked fine under WinXP, but the external monit