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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:50:25+00:00 2026-05-21T17:50:25+00:00

My question is why or how i can make listenerList value as 1 or

  • 0

My question is why or how i can make “listenerList” value as 1 or 2, so that i can track and get status of that instance from alert class with the help of vector()? ex: listenerList is my process id to track them, but its always value of 0

Here is whole code, not working to see the output: “it WORKS!!!, if i can reach here!!!”:

[updated after suggestion, but still same, not working]

1) Interface

public interface Listener
{
    public void registered();
    public void connected(String IP,int Port);
    public void disconnected();
}

2) Interface extending

public class alert implements Listener
{
  public void  registered() 
  {System.out.println("it WORKS!!!, if i can reach here!!!"); System.exit(0);}
  public void connected(String IP, int Port) 
  { throw new UnsupportedOperationException("Not supported yet.");}
  public void disconnected() 
  {  throw new UnsupportedOperationException("Not supported yet.");   }
}

3) Main class to use

public class Provider extends Thread
{
  public Vector listenerList;
  public alert  alert;   

  public Provider(String userName) throws Exception{ listenerList = new Vector();   
    addListener(alert);
  }
  public void addListener(Listener ls)    {     listenerList.addElement(ls);}  
  public void removeListener(Listener ls) { listenerList.removeElement(ls); }  

  public void run()
  {
    while(running)
    {
      fireRegisteredEvent(); // shows now value of 1, but does not do exit(0);
    }
  }  

  private void fireRegisteredEvent() 
  {
      System.out.println("Fireing Registration: " + System.currentTimeMillis()); 
      System.out.println("Fireing Registration: " + listenerList.size());

      for (int i = 0; i < listenerList.size(); i++) 
      {              
          alert.registered();  
          System.exit(0);                  
      }

  }  
}

4) Action

private Provider multiinstance;
multiinstance = new Provider("Why are you not triggering: System.exit(0);??????");
multiinstance.start();

5) Output

Fireing Registration: 1303646370073
Fireing Registration: 1

….

6) Expecting result:

a) output: System.out.println("it WORKS!!!, if i can reach here!!!");
OR
b) listenerList.size() value is either 1 or 2?!!
OR
c) alert class and interface should react? no?? if not how i can ??
  • 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-21T17:50:26+00:00Added an answer on May 21, 2026 at 5:50 pm

    Because you never instantiated a listener and assigned it to one of the providers. In other words you never call addListener(...) and thus no listener can be triggered.

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

Sidebar

Related Questions

Quick question, how can I make this valid : if($this->datos->bathrooms == 1½){$select1 = JText::_(
Brief question What command can I use to make my DataSet refresh it's connection
My question is pretty simple: How can I write a function once and make
I am starting this question to try and make a central point developers can
My question can be boiled down to, where does the string returned from stringstream.str().c_str()
This is quite a straight forward question that I can't seem to find a
Just like the question how can make it look glassy? I just want one
When reading Jon Skeet 's answer to this particular question How can I make
I don't know where exactly to ask this question: How can i make gameplay
I have a very simple question: How can I make this code more simple

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.