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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:38:26+00:00 2026-06-13T10:38:26+00:00

I want to use java nio in java ee. But I don’t know how

  • 0

I want to use java nio in java ee.
But I don’t know how to do it right.
I need to after server has deploy java.nio.selector always listens the port and processing socket connection.
I try do it there:

@Singleton
@Lock(LockType.READ)
public class TaskManager {

    private static final int LISTENINGPORT;

    static {
        LISTENINGPORT = ConfigurationSettings.getConfigureSettings().getListeningPort();
    }

    private ArrayList<ServerCalculationInfo> serverList;

    public TaskManager() {
        serverList = new ArrayList<ServerCalculationInfo>();
        select();
    }

    @Asynchronous
    public void select() {
        try {
            ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
            Selector selector = Selector.open();
            serverSocketChannel.configureBlocking(false);
            serverSocketChannel.socket().bind(new InetSocketAddress(LISTENINGPORT));
            serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);

            while (true) {
                try {
                    selector.select();
                } catch (IOException ex) {
                    Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
                    break;
                }
                Iterator it = selector.selectedKeys().iterator();
                while (it.hasNext()) {
                    SelectionKey selKey = (SelectionKey) it.next();
                    it.remove();
                    try {
                        processSelectionKey(serverSocketChannel, selKey);
                    } catch (IOException e) {
                        serverList.remove(serverCalculationInfo);
                    }
                }
            }

        } catch (IOException e) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        } catch (Exception e) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        }
    }
}

It don’t work correctly. The process hangs during deploy and redeploy application possible only after restart Glassfish.
How can I do right it?

  • 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-13T10:38:29+00:00Added an answer on June 13, 2026 at 10:38 am

    It works correctly if invoke @Asynchronous method from the @PostConstructor:

    @PostConstruct
    public void postTaskManager() {
        serverList = new ArrayList<ServerCalculationInfo>();
        select();
    }
    

    instead of invoke it from constructor.
    But class must be without @Startup annotation.

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

Sidebar

Related Questions

I want to use java platform and I don't know what else I need
I want to use java.nio.channels.FileChannel to read from a file, but I want to
I want to use Java Locale for internationalization with Russian language, but Locale has
I don't want to use any Java code, I just want to use <jsp:include>
I know that in java when u want to create a high performance server
I want to use the new java.nio.file.Files.walkFileTree in Scala. And I was even successful:
I want to install and use java on a linux server. specifically, for creating
I want to use java standard library, and as much as I know, its
I want to use Java Mail to send an email but I want to
I want to use java key store to save keys and certificates. can anybody

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.