Unable to read AsynchronousSocketChannel after getting timeout exception

i am trying to read some data on the server using a AsynchronousSocketChannel .
I have this scenario :
1- Call channel.read : this will print "Received"
2- Call channel.read : this should fail due to timeout exception.
3- Call channel.read : I am sending data in this case but I got the exception "Reading not allowed due to timeout or cancellation"
Below is the source code
My environment is :
OS : Windows 7
JDK :
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)
package com.qmic.asynchronous;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class NIOChannel {
     public static void main(String[] args) {
          try{
               MyAsynchronousTcpServer server = new MyAsynchronousTcpServer();
               Thread serverThread = new Thread(server);
               serverThread.start();
               Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), 9001, InetAddress.getByName("127.0.0.1"), 9003);
               socket.setSoTimeout(30000);
               socket.setKeepAlive(true);
               if (socket.isConnected()){
                    PrintWriter dos = new PrintWriter(socket.getOutputStream());
                    InputStream input = socket.getInputStream();
                    byte[] buffer = new byte[1024];
                    // Data of the first call
                    dos.print("ABCDEFGH");
                    dos.flush();
                    byte[] data = new byte[50];
                    socket.getInputStream().read(data);
                    // Print the result from server, written in handler of first read operation.
                    System.out.println("Result is:" + new String(data));
                    if (data.length > 0){
                         Thread.sleep(10000); // Wait for 10 Seconds so the second read on the server will fail.
                    // Data of the third call
                    dos.print("ABCDEFGH");
                    dos.flush();
          }catch(Exception ex){
               ex.printStackTrace();
     class MyAsynchronousTcpServer implements Runnable{
          final int SERVER_PORT = 9001;
          final String SERVER_IP = "127.0.0.1";
          private int THREAD_POOL_SIZE = 10;
          private int DEFAULT_THREAD_POOL_SIZE = 2;
          ConcurrentLinkedQueue<ListenHandler> handlers = new ConcurrentLinkedQueue<ListenHandler>();
          boolean shutDown = false;
          public void run(){
               //create asynchronous server-socket channel bound to the default group
               try {
                    // Create the ChannelGroup(thread pool).
                    ExecutorService executorService = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
                    AsynchronousChannelGroup group = AsynchronousChannelGroup.withCachedThreadPool(executorService, DEFAULT_THREAD_POOL_SIZE);
                    AsynchronousServerSocketChannel asynchronousServerSocketChannel =
                         AsynchronousServerSocketChannel.open(group);
                    if (asynchronousServerSocketChannel.isOpen())
                         //bind to local address
                         asynchronousServerSocketChannel.bind(new InetSocketAddress(SERVER_IP, SERVER_PORT));
                         while(!shutDown){
                              Future<AsynchronousSocketChannel> asynchronousSocketChannelFuture =asynchronousServerSocketChannel.accept();
                              final AsynchronousSocketChannel channel = asynchronousSocketChannelFuture.get(); // Timeout can be specified in the get() function, thread is blocked here
                              System.out.println("New channel created successfully");
                              // First call, should print Result of call 1 is : 10 (size of ABCDEFGH)
                              ByteBuffer buffer1 = ByteBuffer.allocateDirect(250);
                              channel.read(buffer1, 5, TimeUnit.SECONDS, null, new CompletionHandler<Integer, Object>() {
                                   @Override
                                   public void completed(Integer result, Object attachment) {
                                        System.out.println("Result of call 1 is :" + result);
                                        ByteBuffer response = ByteBuffer.wrap("Received".getBytes());
                                        channel.write(response);
                                   @Override
                                   public void failed(Throwable exc, Object attachment) {
                                        exc.printStackTrace();
                              Thread.sleep(3000);
                              // Second read, should print error InterruptedByTimeoutException
                              ByteBuffer buffer2 = ByteBuffer.allocateDirect(250);
                              channel.read(buffer2, 5, TimeUnit.SECONDS, null, new CompletionHandler<Integer, Object>() {
                                   @Override
                                   public void completed(Integer result, Object attachment) {
                                        System.out.println("Result of call 2 is :" + result);
                                   @Override
                                   public void failed(Throwable exc, Object attachment) {
                                        exc.printStackTrace();
                              Thread.sleep(9000);
                              // Second read operation was failed, no try to read again . AN EXCEPTION IS THROWN HERE : Reading not allowed due to timeout or cancellation
                              ByteBuffer buffer3 = ByteBuffer.allocateDirect(250);
                              channel.read(buffer3, 5, TimeUnit.SECONDS, null, new CompletionHandler<Integer, Object>() {
                                   @Override
                                   public void completed(Integer result, Object attachment) {
                                        System.out.println("Result of call 3 is :" + result);
                                   @Override
                                   public void failed(Throwable exc, Object attachment) {
                                        exc.printStackTrace();
                    else
                         System.out.println("The asynchronous server-socket channel cannot be opened!");
               catch (Exception ex)
                    ex.printStackTrace();
                    System.err.println(ex);
     }

I'm having the same "Unable to read the SIM card" issue. My phone is less than two months old, the unable to read SIM card issue started about a week after I purchased the phone. That was followed by a host of erratic, sporadic issues to the phone becomes unusable and the only way to temporarily fix it is to remove the battery for a few seconds.  I've gone through the factory reset with Verizon reps where I purchased the phone from as well as with a Verizon online Chat representative. In a nutshell, I got a ticket to send the phone back to Samsung in Plano, Texas to get the phone fixed, I am going to do that today because this problem is ridiculous.

Similar Messages

  • Getting timeout exception

    Hi i am gettig below error in logs-
    ####<Feb 20, 2013 3:33:56 AM EST> <Warning> <Socket> <server1> <managed-m04> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tunin
    g)'> <<WLS Kernel>> <> <> <1361349236603> <BEA-000449> <Closing socket as no data read from it on 10.36.2.11:1,261 during the configured idle timeout of 5 secs>
    ####<Feb 20, 2013 3:33:56 AM EST> <Warning> <Socket> <server1> <managed-m04> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tunin
    g)'> <<WLS Kernel>> <> <> <1361349236603> <BEA-000449> <Closing socket as no data read from it on 10.36.2.11:1,377 during the configured idle timeout of 5 secs>
    ####<Feb 20, 2013 3:33:56 AM EST> <Warning> <Socket> <server1> <managed-m04> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tunin
    g)'> <<WLS Kernel>> <> <> <1361349236603> <BEA-000449> <Closing socket as no data read from it on 10.36.2.11:1,272 during the configured idle timeout of 5 secs>
    can someone please help me out to get this issue fixed.
    Thanks in Advance.
    Regards,
    Sarath

    Hi,
    it is not the problem with you, for time out problems there may be a many reasons....for example due to huge data checking or taking lot of time to complete the program execution it will give this type of shortdumps, no need to apply any SAP notes.
    contact your BASIS team, in ever server they put some time stamp for Tcodes, it it exceeds then it will go for short dumps.
    Reward if useful.
    Thanks,
    Sreeram.

  • How to continue the loop after getting the exception NO_DATA_FOUND

    I am inserting 2000 employees attendance data into table through procedure by validating the shifts assigned some times if employee doesn't have shift it raising NO_DATA_FOUND exception, so now I am inserting the details of the employee into one table as a log.
    my question is if 2000 transactions are inserting if exception raised at 1000 record as "NO_DATA_FOUND" is it remaining records will insert into the table? or it will exit from the procedure and stops remaining 1000 transactions?, please advice if any other way to continue the remaining transactions
    oracle version: 11 G R2, OS: Windows 2008 R2

    Do your select statement in a seperate begin...end block, you can cath the excption in the block and do your logging there.
    Something like this
    --just an example from scott/tiger
    Declare
    CNT number := 7851 ;
    vname varchar2(25);
    ins_flag boolean ;
    BEGIN
    while cnt  <= 7935 and cnt >=7850
    LOOP
    Begin
    select ename into vname from emp where empno=cnt ;
    ins_flag := true;
    exception
      when no_data_found then
    -- dbms_output.put_line('no data');
    ins_flag := false;
    end;
      if ins_flag then
      --do insert here
      dbms_output.put_line('do your insert here');
    else
      dbms_output.put_line('no insert');
    end if;
      cnt := cnt+1 ;
    END LOOP;
    end;

  • Broken Reader functionality after getting an Acrobat Form back.

    Hi,
    we have recently run into the problem that several completed Acrobat Forms with enabled extended Reader features (for saving the form from Reader) came back with the Reader features broken:
    The main problem lies in the fact that we set some textboxes to allow multi-line entry and to scroll long text. (We were pretty certain that some users would need more space than there is available).
    This leaves us with a completed form in which only users with Acrobat Standard or Pro can access the complete text entries.
    I tried to reproduce the error but failed. I did use a single line of JavaScript as an page entry event on the first page to turn off the field overlay.
    That's more or less all there's special about the file. At least there seems to be some kind of regularity in the behavior: a second version of the same form from one of the users causing problems was broken, too.
    Unfortunately, I don't know any details on which reader version the users filling out the form have.
    I also can't share the broken foms since the contents are pretty confidential.
    Has anyone else experienced something similar?
    Many thanks and best regards,
    Mike

    Yes, it should be a custom calculate script. Here's a sample one below. It assumes the fields are named "A1", "A2", ..."A23". You will have to change the value of the "row" variable for each script, which is currently set to 2, meaning it should go in the A2 field. This really should be a function in a document-level JavaScript to it can be called by passing the row number or extracting it from the value of event.target.name, but it should get you started. Note that I didn't test it, so it might need some tweaking:
    // Custom Calculation script for row 2
    (function () {
        // Row number of this field
        var row = 2;
        // Get the value of the A column field
        var sVal = getField("A" + row).valueAsString;
        var sVal2;
         // Set this field value to  "O/D" if blank
        if (!sVal) {
            event.value = "O/D";
            return;
        // Scan the previous rows to see if any match this value
        for (var i = 1; i < row; i += 1) {
            // Get the current row value
            sVal2 = getField("A" + i).valueAsString;
            // See if it matches
            if (sVal2 === sVal) {
                event.value = "Deobligate";
                return;
         // No match was found. so set this field value to "Obligate"
        event.value = "Obligate";

  • Bridge unable to read cache, after clicking refresh another problem

    I tried purging cache did not fix the problem. I click the refresh button in bridge to see if that might the problem. Now not only can bridge not read cache it can not build criteria, the circle just keeps spinning and spinning. I cannot open any folders therefore cannot view any of my images. Help Please!!

    No. The cache is where Bridge stores the thumbnails not the photos.
    If you purge the cache Bridge will regenerate the thumbs when visiting the folders.

  • When I go online to my bank my statments are unable to read as they get overlapped by the questions on the right, If I log in from Internet explorer the full page is shown, This is the same for the Daily Mail Rewards club.

    I use Windows XP professional, When I use Firefox to go to my Barclay bank statements, they are unreadable as the page with the amounts on is partly covered by the Questions on the right of the page, I also have this problem with the Daily Mail rewards club, If I login to my account from Internet Explorer it works fine for both, this is without making any changes to my setup.

    What you are experiencing is 100% related to Malware.
    Sometimes a problem with Firefox may be a result of malware installed on your computer, that you may not be aware of.
    You can try these free programs to scan for malware, which work with your existing antivirus software:
    * [http://www.microsoft.com/security/scanner/default.aspx Microsoft Safety Scanner]
    * [http://www.malwarebytes.org/products/malwarebytes_free/ MalwareBytes' Anti-Malware]
    * [http://support.kaspersky.com/faq/?qid=208283363 TDSSKiller - AntiRootkit Utility]
    * [http://www.surfright.nl/en/hitmanpro/ Hitman Pro]
    * [http://www.eset.com/us/online-scanner/ ESET Online Scanner]
    [http://windows.microsoft.com/MSE Microsoft Security Essentials] is a good permanent antivirus for Windows 7/Vista/XP if you don't already have one.
    Further information can be found in the [[Troubleshoot Firefox issues caused by malware]] article.
    Did this fix your problems? Please report back to us!

  • Why do I get timeout when deploying SQL Server data source in Weblogic Admin Console?

    Hi all
    I'm attempting connectivity between WLS 10.3.6.0 and SQL Server 2008R. I've downloaded sqljdbc4.jar and added to the end of the Weblogic Classpath in commEnv.cmd. Then I set up a data source in Admin Console and pressed the Test Data Source button - success. But when I tick the box to deploy to AdminServer it hangs for ages and I get timeout exception.
    Any ideas?
    Many thanks
    James

    Make sure the web server settings between the QA and the Production servers are also compatible.
    I suspect your suspecion about permissions is the closest to the answer.  But this is a little out of my depth of expertise.
    Realize that ColdFusion default behavior is to NOT generate and actual swf FILE.  Rather what it does is generate the swf content in memory and directly deliver it to the client.  But if the web server is configured to look for an actual file system file you may have a clash going on

  • When opening Bridge (CS6) I get the following message: "Bridge encountered a problem and is unable to read the cache. Please try purging the central cache in Cache Preferences to correct the situation" I tried and after selecting purge cache it does not a

    When opening Bridge (CS6) I get the following message: "Bridge encountered a problem and is unable to read the cache. Please try purging the central cache in Cache Preferences to correct the situation" I tried and after selecting purge cache it does not allow me to select OK. Also Bridge keeps saying "Building Criteria" with the spinning wheel and nothing happens. I tried uninstalling and reinstalling to no avail. Please help:)

    Maybe a Preferences reset can help:
    Numerous program settings are stored in the Adobe Bridge preferences file, including display, Adobe Photo Downloader, performance, and file-handling options.
    Restoring preferences returns settings to their defaults and can often correct unusual application behavior.
    Press and hold the Ctrl key (Windows) or the Option key (Mac OS) while starting Adobe Bridge.  
    In the Reset Settings dialog box, select one or more of the following options:  
      Reset Preferences 
    Returns preferences to their factory defaults. Some labels and ratings may be lost. Adobe Bridge creates a new preferences file when it starts.
    Purge Entire Thumbnail Cache
    Purging the thumbnail cache can help if Adobe Bridge is not displaying thumbnails properly. Adobe Bridge re-creates the thumbnail cache when it starts.
    Reset Standard Workspaces
    Returns Adobe predefined workspaces to their factory default configurations.
    Click OK, or click Cancel to open Adobe Bridge without resetting preferences.   

  • How to get remaining time for baton after setting timeOut property

    Hello,
    Is it possible to get the remaining time for baton after setting timeOut, or do I have to maintain a separate Timer for that?
    Been following this excellent tutorial here http://tv.adobe.com/watch/adc-presents/create-shared-forms-in-livecycle-collaboration-serv ice/

    Thanks Nigel, before reading your reply, I came up with something like this, but it seems extending the Baton class is not enough, as I would need my own BatonProperty as well that uses this extended Baton class...
    Also attempted to get some help here http://stackoverflow.com/questions/7116814/actionscript3-lccs-how-to-access-property-paren t-class-protected-var/7116882#7116882
    Could this be made into a feature request for Baton and BatonProperty, se we could easily get the remaining time please?   I guess I can wait for a future release.
    /custom as file /
    package com.mysite.BatonExtender
         import com.adobe.rtc.sharedModel.Baton;
         import flash.events.TimerEvent;
         public class BatonExtender extends Baton
              public function BatonExtender()
              super();
              _autoPutDownTimer.addEventListener(TimerEvent.TIMER,countDown);    
              trace("CURRENT TIMER:"+_autoPutDownTimer.currentCount);
              trace("BATONEXTENDER added");
              public function countDown(p_evt:TimerEvent):void {
                   trace("TRACING START countDown....");
                   if (_autoPutDownTimer.running) {
                        trace(_autoPutDownTimer.currentCount);
                        //sharedTimer.value = String(90 - _autoPutDownTimer.currentCount);
                   trace("TRACING END....");

  • I got an internet connection on my phone. After getting the internet connection, I was unable to make a call or check the missed calls that I got. Please help me resolve this problem.

    I got an internet connection on my phone. After getting the internet connection, I was unable to make a call or check the missed calls that I got. Please help me resolve this problem.

  • After getting 4G with AT&T I am unable to join my network and get the error message: Unable to  join the network "Jude". How do I fix this? Thank you

    After getting 4G with AT&T I am unable to join my network and get the error message: Unable to  join the network "Jude". How do I fix this? Thank yo

    Try power-cycling your wireless router (unplg for 30 seconds, plug back in).  Here's a longer list of troubleshooting steps: http://support.apple.com/kb/TS1398.

  • Unable to read SIM card after latest update

    I downloaded the most recent android update on my Samsung Galaxy Note 4 on 12/10.  Since that update, i've gotten the message "Unable to read the SIM card.  Please restart your phone to read the card" a half-dozen times.  The timing between the messages is sparatic (one time it was a few hours between messages, another time a full day, then 12 hours the third time, etc...).
    Is anyone else experiencing this issue?  Is there a simple fix to this (such as just getting a new SIM card from Verizon)?  I'd like to think that the update wasn't the culprit of this, but I've had my Note 4 since the initial release, and it's only started happening since the last update.
    Any help would be greatly appreciated.  Thanks!

    I'm having the same "Unable to read the SIM card" issue. My phone is less than two months old, the unable to read SIM card issue started about a week after I purchased the phone. That was followed by a host of erratic, sporadic issues to the phone becomes unusable and the only way to temporarily fix it is to remove the battery for a few seconds.  I've gone through the factory reset with Verizon reps where I purchased the phone from as well as with a Verizon online Chat representative. In a nutshell, I got a ticket to send the phone back to Samsung in Plano, Texas to get the phone fixed, I am going to do that today because this problem is ridiculous.

  • HT203075 im unable to sync music apps videos into iphone 6 whereas im able sync into my ipod touch 4G.When im trying to sync into my iphone 6 im getting a dialogue box asking me to authorize....Im unable to sync even after authorizing.

    im unable to sync music apps videos into iphone 6 whereas im able sync into my ipod touch 4G.When im trying to sync into my iphone 6 im getting a dialogue box asking me to authorize....Im unable to sync even after authorizing it.Dialogue box appears again and again...

    I read your entire message, and my mom's iPhone 5 does this exact same thing. When the idiot at the AT&T store transferred her data (well, most of it) to her new phone, he DID NOT use her latest iCloud backup like he should have, but used some features in "Bump" to move things across. So, in my opinion, it's not worth the hassle of restoring it as a new device as Tim suggests. That's just the easy answer. Here's something odd about hers. It seems to do this, when she's using her bluetooth earpiece (a Jawbone Icon), but not when she's got bluetooth disabled on the iPhone 5 and holding down the "Home" button to activate Siri. If she uses her Jawbone bluetooth earpiece to activate Siri, the answer that Siri presents on the phone's screen will only stay on for about five seconds, then dim, then go blank -- and she has to "swipe to unlock" and, of course, the Siri information is gone. Not so if she uses the Home key to activate Siri.

  • After upgrading to Lion, I am unable to read burned DVDs. Any idea what is wrong?

    While I was using Snow Leopard, everything was working fine; but after upgrading to Lion, my Mac Mini (2010) is unable to read any disks that have been burned. All store purchased disks work fine, but nothing I have tried has worked for the burned ones. Does anyone have any idea what may be wrong?

    Well, I did notice a few things about the disk I used that were on that list. I'm going to try burning a new copy on a new disk that has few to no scratches, not mark on it, and keep it off max speed. I'll get back to you when it's done. That may take a while seeing as it's an ISO that I'm burning and it took a good 15 minutes at max speed.

  • TS4268 After the update I am unable to log in to get iMessages. It says "Could not sign in. Please check your network connection and try again". My phone is connected to Wi-fi. What should I do?

    After the update I am unable to log in to get iMessages. It says "Could not sign in. Please check your network connection and try again". My phone is connected to Wi-fi. What should I do?

    Hi andrea110,
    Welcome to the Support Communities!
    The article below may be able to help you with this issue.
    Click on the link to see more details and screenshots.
    The settings are the same for iOS 7:
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/TS2755?viewlocale=en_US
    Cheers,
    - Judy

Maybe you are looking for