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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:59:13+00:00 2026-05-27T04:59:13+00:00

The netty documentation suggest using instance variables in ChannelHandlers to keep track of channel

  • 0

The netty documentation suggest using instance variables in ChannelHandlers to keep track of channel state. It doesn’t mention that you should use volatile variables or use any other synchronization technique to assure that there is a consistent view across threads.

For instance using this handler on a per-connection basis:

class Handler extends SimpleChannelUpstreamHandler {
        int count = 0;

        @Override
        public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
            ++count;
        }
}

I would expect that many different threads from a netty thread pool would be calling this method, although not concurrently, and could potentially see an inconsistent view, resulting in an inaccurate count.

Is this the case? or is there some kind of synchronization going on inside of netty that would cause the write to the count field to be flushed?

  • 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-27T04:59:14+00:00Added an answer on May 27, 2026 at 4:59 am

    If you do not have an executor in your pipeline, and are executing your handlers purely in the I/O worker threads, then you’re fine as Netty guarantees that a given pipeline instance is always called back from the same worker thread.

    If you’re adding an execution handler to your pipeline then you are ok if you’re using Netty’s OrderedMemoryAwareThreadPoolExecutor.

    If you are accessing your pipeline from a non-Netty thread, or you have a non-OrderedMemoryAwareThreadPoolExecutor in your pipeline then you need synchronisation.

    I recommend taking a look through the following threads on the Netty user forum archives.

    http://netty.markmail.org/search/?q=Memory+visibility+in+handlers#query:Memory%20visibility%20in%20handlers+page:1+mid:cmtw5omcxbg67sho+state:results

    http://netty.markmail.org/search/?q=Periodic%20TimerTask%20in#query:Periodic%20TimerTask%20in+page:2+mid:vwahepiois4eqwkp+state:results

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

Sidebar

Related Questions

Does netty have built-in support for this somehow? If it doesn't have, where should
When using Netty , I was surprised that if I use reuseAddress option, it
I have a network server that was implemented using Jboss Netty. It servers the
I am using Netty as backend in a Java-based Usenet client. The library is
My TCP server is implemented using Netty. My client using vanilla java.net.Socket to connect
I have a written a very simple UDP Server using Netty - it quite
I'm looking for a recommendation on the best netty class(es) to use that support
I noticed that Netty has some internal Concurrent HashMap utilities. I'm curious why Netty
I am coding board game server using Netty. Using TCP at every part of
Is it possible to write to Netty channel without creating unnecessary ChannelFuture? (Without generating

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.