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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:23:15+00:00 2026-05-27T13:23:15+00:00

I have the following problem. Given a Interface EventNotifier for the Observer Pattern: public

  • 0

I have the following problem. Given a Interface EventNotifier for the Observer Pattern:

public interface EventNotifier {
    void newEvent(final String value);
}

A class, which implements this Interface, can register at another class, which calls very often the method newEvent. The Interface is given by a external library, so I cannot change it. Up to now I implemented it with an anonymous class:

Thread t = new Thread(new Runnable() {

    @Override    
    public void run() {

      watcher = new Watcher(new EventNotifier() {

          @Override
          public void newEvent(String value) {
              //do some stuff
              //will be called more than 20 times per second
          }
       });
 });
 t.start();

For better code readability I would like to expose this anonymous class into a new class, which extends Thread (because the handling should be parallel to other things).

How can I write a Thread, which does nothing (no endless-loop etc.), but wait for calling the newEvent method? The problem is, that newEvent will be called more than 20 times a second, so I cannot start a new thread for each call but the whole thing should be in a thread.

I hope you get the problem and somebody can help me.

  • 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-27T13:23:16+00:00Added an answer on May 27, 2026 at 1:23 pm

    What makes your post confusing is that the EventNotifier is in fact an observer/listener (it receives the event, it doesn’t fire them), and the Watcher is in fact the notifier (it’s the watcher that creates an event and calls the newEvent method).

    I’ll use the terms observable and observer from now on. The observable fires events, and thus calls the observer’s newEvent method.

    If you want the event handling to be done in a separate thread, use a BlockingQueue. Start a thread that loops endlessly, and tries to take() from the queue at each iteration. Register an observer to the observable, which simply takes the received event and put() it in the blocking queue.

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

Sidebar

Related Questions

I have the following problem: I am given a tree with N apples, for
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem using template instantiation [*]. file foo.h class Foo {
Just imagine you have the following class [DataContract] public class NamedList { [DataMember] public
I have the following generic question Here is a my generic message interface. public
I am writing Eclipse plugins for Java, and have the following problem: Given an
Given the following hypothetical situation: class ClassParent { } interface IClassProvider { ClassParent Get();
I have following problem: I have a NSDictionary here: @interface ENSListViewController : UIViewController <UITableViewDataSource,
If we have the following sample application: interface ITest { string Test { get;
I have the following interfaces defined: public interface IAudit { DateTime DateCreated { get;

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.