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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:38:49+00:00 2026-05-30T06:38:49+00:00

First, I’ll explain the situation and the logic that I’m trying to implement: I

  • 0

First, I’ll explain the situation and the logic that I’m trying to implement:

  • I have multiple threads, each put result of it work, some object called Result into queue QueueToSend

  • My NettyClient runs in thread and takes Result from QueueToSend every 1 milisecond and should connect to server and send a message, that is created from Result.
    I also need this connections to be asynch. So I need the Result list to be known by NettyHandler to send right message and process right result and then again send response.

So I initialize NettyClient bootstrap

bootstrap = new ClientBootstrap(
                new NioClientSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));

and sets pipeline once when app starts.
Then, every milisecond I take Result object from QueueToSend and connect to server

ChannelFuture future = bootstrap.connect(new InetSocketAddress(host,port);
ResultConcurrentHashMap.put(future.getChannel().getId(), result);

I decided to use static ConcurrentHashMap to save every result object taken from QueueToSend assosiated with channel.

The first problem takes place in NettyHandler in method channelConnected, when I am trying to take Result object assosiated with channel from ResultConcurrentHashMap.

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
       Channel channel = ctx.getPipeline.getChannel();
       Result result = ResultConcurrentHashMap.get(channel.getId());
}

But sometimes result is null (1 of 50), even thought it should be in ResultConcurrentHashMap. I think it happens cause that channelConnected event happens before NettyClient runs this code:

ResultConcurrentHashMap.put(future.getChannel().getId(), result);

May be it will not appear if I run NettyServer and NettyClient not on localhost both, but remotely, it will take moretime to estabilish the connection. But I need a solution for this issue.

Another issue is that I am sending messages every 1 milisecond asynchromously and I suppose that messages are may be mixed and server can not read them properly. If I run them one by one it will be ok :

future.getChannel().getCloseFuture().awaitUninterruptibly();

But I need asynchromus sending, and process right results, assosiated with channel and send responses.
What should I implement?

  • 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-05-30T06:38:50+00:00Added an answer on May 30, 2026 at 6:38 am

    ChannelFutures are executed asynchronously before the events get fired. For example channel connect future will be completed before firing the channel connected event.

    So you have to register a channel future listener after calling bootstrap.connect() and write your code in the listener to initialize the HashMap, then it will be visible to the handler.

            ChannelFuture channelFuture = bootstrap.connect(remoteAddress, localAddress);
    
            channelFuture.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    resultConcurrentHashMap.put(future.getChannel().getId(), result);
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I am using Windows XP. I have multiple hard drives and it
First Im a noob in LINQ ! Then, the thing is that I have
First of all I have seen that there are many questions about unrecognized selector
First of all, I'm uploading multiple images that goes through a for loop by
First, I have a list of QWidget s that I won't know the length
First of all, I know how to build a Java application. But I have
First let me say that I really feel directionless on this question. I am
First off, I'm working on an app that's written such that some of your
First I want to thank you guys here, because your posts have gotten me
First, I have a dbcontext factory which is defined public class DatabaseFactory : Disposable,

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.