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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:42:24+00:00 2026-05-24T04:42:24+00:00

I have two classes. In Class1 I have a thread and in Class2 I

  • 0

I have two classes. In Class1 I have a thread and in Class2 I have to pause/lock that thread which will be started immediately after the login. In my scenario, after the login (which is implemented in Class2) the Thread has to be made wait for some more additional login and getting data from DB. Please let me know how to control the Thread running in the other class from different class.

Class1:

public class Class1{
 Class2 cls2 = new Class2();
 cls2.logon();
 // login which will start the thread in the Class2 as well
 // Please suggest what should be done here

 // DB realated stuff need be done here
 // Have to unlock/resume the thread in Class2
}

Class2:

public class Class2{
 public void receiveMessage(String str){
   new StringProcessor(str);
 }

 public class StringProcessor implements Runnable {
  //do some stuff but have to wait for the DB related stuff in Class1
 }

 public void logon(){
  //Will create/logon the connection and the message will be start arriving
 }

}

Actually after login there will be TCP/IP connection to receive the messages. The method receiveMessage() will be called whenever the message arrives. But I have to pause that

Cheers,
Sakthi. S

  • 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-24T04:42:25+00:00Added an answer on May 24, 2026 at 4:42 am

    There are several approaches.

    The wrong one is to use Thread.suspend/resume/destroy since they are deprecated and deadlock-prone.

    You can either…

    1. Implement your own signaling mechanism by using Object.wait, Object.notifyAll.
    2. Use the Semaphore class or any other class in java.util.concurrent that suits your needs.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes - one that runs in the main thread and performs
I have two classes that I am testing (let's call them ClassA and ClassB).
I have implemented the two classes shown at http://tomcat.apache.org/tomcat-6.0-doc/aio.html which gives a messenger application
What I'm talking about here are nested classes. Essentially, I have two classes that
I have two classes that communicate with each other (processes in each class depend
I have two classes class A { public string something { get; set; }
I have a two classes: public class Question { public IList<Answer> Answers { get;
I have these two classes public class Person { } public class Company {
Let's say we have these two classes: public class Base { public static int
greetngs, i have two classes: [Serializable] public class FireGridUnit { public GridUnit FireGridLocation {

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.