Results 1 to 2 of 2
  1. #1
    patluze is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default calling a client on a specific thread

    I'm porting a .NET project to java and I’m looking for the best way to notify clients of an event on a thread that they specify.

    In .NET my event notification class has a set_SynchronizingObject method that takes as a parameter the .NET ISynchronizeInvoke interface, which has the InvokeRequired and Invoke methods, among others, to achieve this. The client initializes my event notification class with a reference to a listener and an instance of the ISynchronizeInvoke interface. To notify the client of an event, the event notification class does something like this:

    Event notification class

    SomeMethod

    if (clientImplementationOfISynchronizeInvoke.InvokeRe quired)
    create an object that represents MyMethod
    clientImplementationOfISynchronizeInvoke.Invoke(ob jectThatRepresentsMyMethod)
    else
    call MyMethod

    MyMethod
    call listener

    The client’s implementation of ISynchronizeInvoke::Invoke is responsible for calling MyMethod on the appropriate thread.


    My questions are:

    1) Is there something similar to ISynchronizeInvoke in java?

    2) If not, is there a “best practices” way to implement this functionality?

    3) A more general question -- how do I invoke a method on a specific thread?

    Thanks in advance for your thoughts.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    i know of in Java the wait() and notify() methods part of the threading API.

    To have a specific thread invoke something, perhaps we could have that thread invoke wait() on some object and then when we want to have that thread do its thing, we could invoke notify().

    for example,

    Java Code:
    Thread t1 = new Thread(new Runnable() ) {
      public void run() {
        t1.wait();  // will block until we are notified
        // only gets here after we have been notified
      }
    }
    
    // some other thread
    
    t1.notify(); // instruct the thread we want them to run now.

Similar Threads

  1. How to assigne Java thread to a specific cpu core
    By perl0101 in forum Advanced Java
    Replies: 3
    Last Post: 02-03-2010, 09:39 AM
  2. calling thread.sleep stalls main gui
    By jc5 in forum Threads and Synchronization
    Replies: 7
    Last Post: 10-02-2009, 01:10 PM
  3. Replies: 1
    Last Post: 07-17-2009, 08:08 AM
  4. Problem in Thread wakeup of Java NIO Client
    By sranil in forum Networking
    Replies: 0
    Last Post: 04-05-2009, 07:42 PM
  5. TCPIP Client (handling specific exceptions)
    By ravian in forum Networking
    Replies: 3
    Last Post: 11-29-2007, 09:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •