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 8822549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:08:03+00:00 2026-06-14T06:08:03+00:00

According to this post: https://stackoverflow.com/questions/6666659/threading-implications-of-asynchronousbytechannel the java implementation of asynchronous socket channel doesn’t guarantee

  • 0

According to this post: https://stackoverflow.com/questions/6666659/threading-implications-of-asynchronousbytechannel the java implementation of asynchronous socket channel doesn’t guarantee that completion handler gets called in a separate thread. So if you are reading into a byte buffer, how do you get notify() called after wait()?

        class CH implements CompletionHandler<Integer,Integer>
       {            
            public volatile int i = 0;
            public void completed(Integer i, Integer o)
            {
               this.i = i;
               synchronized(this)
                {
                    this.notify();
             }
           }

        public void failed(Throwable t, Integer o)
        {
            this.i = -5;                
            synchronized(this)
            {
                this.notify();
            }
        }

    }

               CH x = new CH();
              synchronized (x) {            
                    while (!(x.i == -1 || x.i == -5)) {
                            aschannel.read(bytebuffer, 5, TimeUnit.SECONDS, null, x);
                             x.wait();                                           
                             if(x.i != -1 && x.i != -5){
                                  bytebuffer.flip();
                                   filechannel.write(bytebuffer.array,0,x.i);
                                   bytebuffer.clear();
                               }
               }     


              }
  • 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-06-14T06:08:04+00:00Added an answer on June 14, 2026 at 6:08 am

    Your program may work, because wait() releases the monitor and allow callbacks to execute.

    However, the whole idea of asynchronous I/O is to free the I/O exchange initiator from waiting (and so holding the thread). If you want to wait anyway, then simply use good old synchronous API. Or call read without CompletionHandler, which returns Future, and wait on that Future.

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

Sidebar

Related Questions

I already saw this post here (http://stackoverflow.com/questions/1398113/sql-select-one-row-randomly-but-taking-into-account-a-weight), but couldnt work it out. Where do
According to this post: https://groups.google.com/forum/?fromgroups#!topic/kivy-users/n7c3thksnzg , it is possible to use Eclipse as an
According to this post , IDEA uses Osmorc to run OSGi frameworks. It, in
According to this post in Recursive Descent vs. LALR , any LALR(k) can be
According to this post , i ask $title. Which are your favorite PHP coding
According to this post on Daring Fireball a new iPhone SDK Agreement release in
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django
I'm using Android 2.3, so according to this post: Streaming Audio from A URL
According to this sample: http://www.codeproject.com/KB/mobile/DeepCast.aspx It's possible to request a gps coordinate (longitude &
According to https://developers.google.com/appengine/docs/python/config/cron cron jobs can run for 10 minutes. However, when I try

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.