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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:09:05+00:00 2026-05-31T12:09:05+00:00

I have a Java thread that I start so it keeps listening to a

  • 0

I have a Java thread that I start so it keeps listening to a socket (considering the a socket read is blocking a thread is needed).

After the Thread receives the data from the socket it needs to call a method from a class.

Now I have two options to do this:

Declare an interface that is passed to the Thread and implemented in a class. When the thread calls the interface method the implementing classes will run it.

Or I can pass the class instance to the Thread as a parameter and then call the class method.

But I wanted to know if the thread blocks while the method is running.

I suppose so but I’m not sure.

I wanted the thread to have a Socket event behavior. What I mean is to only be responsible for reading the data from the socket and fire functions in the main Class, the one that called the Thread.

  • 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-31T12:09:07+00:00Added an answer on May 31, 2026 at 12:09 pm

    Yes, the thread will block while executing the method, so it can not read from the socket at the same time. No information will be lost, the transfer only takes longer and you can get a socket timeout if the computation takes too long.

    If your method takes much time to run, you should execute it in another worker thread. I recommend to use an Executor for that.

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

Sidebar

Related Questions

I have a layered application in Java which has a multi thread data access
Hy!!! I have a endless thread that updated the view. UpdateState.java : package android.skiptvad;
I read that every object in java have a lock.That will be acquired by
I have written a simple Java dispatcher with a daemon thread to handle the
I have this very straight forward question regarding Thread and Timer classes in Java
Java 6 API question. Does calling LockSupport.unpark(thread) have a happens-before relationship to the return
I have Java Map (out of Strings and Ints) objects that I want to
I have a java class that creates a process, called child, using ProcessBuilder. The
Let's say I have to read from a directory that has many large XML
I have an app in java that is nothing but a remote server.The remote

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.