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

  • Home
  • SEARCH
  • 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 8249235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:28:01+00:00 2026-06-07T23:28:01+00:00

I have a packet Listener Thread in Java for UDP packets along with 2-3

  • 0

I have a packet Listener Thread in Java for UDP packets along with 2-3 other threads.

It was running fine till today but now the process javaw.exe has started using CONSTANT 50% CPU.

Here is my code.

public class PacketListenerThread implements Runnable {
    private SocketAddress receivedSocketAddress;
    private DatagramChannel channel;
    private ExecutorService pool;

    public PacketListenerThread(DatagramChannel channel, ExecutorService pool) {
        this.channel = channel;
        this.pool = pool;
    }

    @Override
    public void run() {
        while (true) {
            receivedSocketAddress = null;
            ByteBuffer recvbuf = ByteBuffer.allocate(1400);
            recvbuf.clear();
            try {
                receivedSocketAddress = channel.receive(recvbuf);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (receivedSocketAddress != null) {
                pool.submit(new PacketHandlerRunnable(new TaskObject(receivedSocketAddress, recvbuf)));
            }
        }
    }
}

I have stopped all other threads but this thread still uses “CONSTANT” 50% CPU .

  • 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-07T23:28:03+00:00Added an answer on June 7, 2026 at 11:28 pm

    See Javadoc:

    If a datagram is immediately available, or if this channel is in blocking mode and one eventually becomes available, then the datagram is copied into the given byte buffer and its source address is returned. If this channel is in non-blocking mode and a datagram is not immediately available then this method immediately returns null.

    Maybe your call to channel.receive(recvbuf) does not block, so you are looping at inifite speed which explains your CPU load.

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

Sidebar

Related Questions

I have a java program which sends a udp packet to a server when
I've read a number of articles about UDP packet sizes but have been unable
I have the following UDP broadcast listener running as a static component in a
I have this udp packet: P = <<83,65,77,80,188,64,172,85,30,144,105,0,0,0,50,0,7,0,0,0,115,97,109,112,45,114,112,11,0,0,0,149,78,87,149,82,80,149,118,50,46,50,11,0,0,0,83,97,110,32,65,110,100,114,101,97,115>> 14-15 byte is the players var
I have a small client/server app that sends/receives UDP discovery packets. When a UDP
I have a voice chat which receives rtp packets (each packet contains 20ms of
I have to send a UDP packet and get a response back from UDP
I have a simple udp listener written in c++ using win32 when I compile
I have a basic audiorecord-audiotrack, udp packets voice chat between two android devices. It
I have an app, software defined radio, that broadcasts UDP packets on a port

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.