Synchronizing threads of different JVM

I have two threads running in two different JVMs. Now I want to synchronize these two threads calling a method.
Can any one give me a solution for the same.

I have two threads running in two different JVMs. Now
I want to synchronize these two threads calling a
method.
Can any one give me a solution for the same.Presumably you think that the Java API has such a method. If so then the answer is no.
You could write a bunch of code that uses sockets to send messages back and forth and then have one thread wait for a response. That isn't sychronization however. And conceptually it isn't a good idea to think of it that way either. Threads exist solely within a single process.

Similar Messages

  • Thread in Different Consoles

    Hello!
    I am currently programming an applet with 3 buttons, start, stop and exit. The start button would open a thread that would create a socket connection to the server. The exit button simply closes the applet. The stop button should end the thread made when the start button is clicked.
    After several research regarding how to stop the thread, I can't still find solutions for this scenario:
    1. Run the applet, start the thread for the connection. Exit.
    2. Run the applet, stop the thread and its connection. Exit.
    *Note: I am running in different dos consoles
    Is this possible? To stop the thread in a different console? I know that different jvm's are completely separated, but are there ways?
    The only way I think of right now is to create a table in the database to log the states. Upon starting there will be a thread that monitors the table if there is a SHUTDOWN_INITIATED value, then close the connection.
    Are there any other solutions? What can you suggest?
    Thanks in advance.
    Ronron

    It is possible to control one thread running in one JVM from another - the endevour is difficult.
    On the other hand, if you use the two applets from the browser - you can get reference to the other applet through the AppletContext interface and then proceed to stop the thread.
    Ironluca
    [email protected]

  • Can't stop synchronized threads with I/O read and write

    I have two synchronized threads which doing read and write from and into a file.
    One thread called "reader" which does reading, encoding, etc from a source file and puts its output in a pre-defined variable. Another called "writer" which puts the reader's output into a file ( not the source file ). Both thread will notify each other when they've finished each of their part. It's similiar to CubyHole example of Java Tutorial example from Sun.
    But somehow it seems like the threads keep spawning and won't die. Even if the source file has been all read and the data has been fully written, calling interrupt(), return, etc has no effect. The threads will keep running untill System.exit() called.
    Is it because the threads were blocked for I/O operation and the only way to kill them is to close the I/O ?
    To be honest, it's not only stop the threads that I want to, I also want to somehow pause the threads manually in the middle of the process.
    Is it possible ?
    Cheers.!!!

    The example code for the problem using 4 classes called :
    - libReadWrite ( class holding methods for aplication operations )
    - reader ( thread class responsible for reading data )
    - writer ( thread class responsible for writing data )
    - myGUI ( user interface class )
    All of them written in different file.
    // libReadWrite
    pubic class libReadWrite {
    private boolean dataReady;
    private String theData;
    //read data
    public synchronized void read(String inputFile) {
    while (dataReady == true) {
    try {
    wait();
    } catch (InterruptedException ex) {}
    RandomAccessFile raf = new RandomAccessFile(inputFile, "r"); // I'm using raf here because there are a lot of seek operations
    theData = "whatever"; // final data after several unlist processes
    dataReady = true;
    notifyAll();
    public synchronized void write(String outputFile) {
    while (dataReady == false) {
    try {
    wait();
    } catch (InterruptedException ex) {}
    DataOutputStream output = new DataOutputStream(new FileOutputStream(outputFile, true));
    output.writeBytes(theData);
    dataReady = false;
    notifyAll();
    //Reader
    public class reader extends Thread {
    private libReadWrite myLib;
    private String inputFile;
    public reader (libReadWrite myLib, String inputFile) {
    this.myLib = myLib;
    this.inputFile = inputFile;
    public void run() {
    while (!isInterrupted()) {
    myLib.read(inputFile); <-- this code running within a loop
    return;
    public class writer extends Thread {
    private libReadWrite myLib;
    private String outputFile;
    public writer (libReadWrite myLib, String outputFile) {
    this.myLib = myLib;
    this.outputFile = outputFile;
    public void run() {
    while (!isInterrupted()) {
    myLib.write(outputFile); <-- this code running within a loop
    try {
    sleep(int)(Math.random() + 100);
    } catch (InterruptedException ex) {}
    return;
    //myGUI
    public class myGUI extends JFrame {
    private libReadWrite lib;
    private reader readerRunner;
    private writer writerRunner;
    //Those private variables initialized when the JFrame open (windowOpened)
    libReadWrite lib = new libReadWrite();
    reader readerRunner = new reader("inputfile.txt");
    writer writerRunner = new writer("outputfile.txt");
    //A lot of gui stuffs here but the thing is below. The code is executed from a button actionPerformed
    if (button.getText().equals("Run me")) {
    readerRunner.start();
    writerRunner.start();
    button.setText("Stop me");
    } else {
    readerRunner.interrupt();
    writerRunner.interrupt();
    }

  • MBeans and MBeanServer in different JVM

    Hi,
    Is it possible that MBeans reside in different JVM and MBeanServer reside on different JVM? If so, then how to get instance of MBean into MBeanServer, as it is needed to register that MBean into server.
    or how its to be done.
    Thanks in advance.Please Help.

    Hi Jahnvi,
    As I have already answered in this thread a few weeks ago:
    http://forum.java.sun.com/thread.jspa?threadID=790563&messageID=4508174#4508174
    what you describe is a use case for MBeanServer federation - aka Cascading.
    You can set up a master agent/sub agent hierarchy where:
    Each "subagent" JVMs has local MBeans registered in its MBeanServer, and starts
    a JMXConnectorServer.
    The "master" JVM (the JVM that the end client sees) uses JMXConnectors to talk to
    access the MBeans registered in the subagents, and creates proxies for these MBeans
    in its local MBeanServer.
    The console then simply needs to connect to the "master" JVM, where it can see
    all proxied MBeans.
    The Java DMK has an API that allows you to set-up and control such a hiearchy.
    A standard feature for federating MBeanServer is also in discussion for JDK 7.
    See more info on my previous post here:
    http://forum.java.sun.com/thread.jspa?threadID=790563&messageID=4508174#4508174
    Hope this helps,
    -- daniel
    JMX, SNMP, Java, etc...
    http://blogs.sun.com/jmxetc

  • Starting a specific managed server with a different JVM.

    Hello!
    We have a Weblogic (11g 10.3.6.0) Domain created using the Configuration Wizard (WL_HOME/common/bin/config.sh). This domain was configured to use Oracle JRockit JVM. So, all managed servers in this domain uses JRockit. But for some test/P.O.C reasons we want to configure a specific managed server (in this same domain) to run on top of Sun HotSpot. We need do this without change the domain's default JVM (Oracle JRockit).
    Is it possible?
    I tried many ways but now I'm a bit confused. Reading the DOC [1] I tried to change the setDomainEnv.sh to set the JAVA_VENDOR ('Sun') and JAVA_HOME (/path/to/sun/jdk). But in this way you change the JVM for whole Domain.
    If I change the Server's configuration using AdminConsole (ServerX>Configuration>Server Start page) and them start it using AdminConsole or NodeManager, it (partially) works. I mean, the server starts using Sun Hotspot JVM, but if you look at the command process used to statrt it, you can see something strange.
    "/opt/Oracle/java/ *jdk1.7.0_07* /bin/java -Dweblogic.Name=server-2 -Dbea.home=/opt/Oracle/Middleware11g -Djava.security.policy=/opt/Oracle/Middleware11g/wlserver_10.3/server/lib/weblogic.policy -Dweblogic.management.server=http://192.168.56.101:7001 -D *java.library.path* = */opt/Oracle/java/jrmc-4.0.1-1.6.0/jre/lib/amd64/jrockit:/opt/Oracle/java/jrmc-4.0.1-1.6.0/jre/lib/amd64:/opt/Oracle/java/jrmc-4.0.1-1.6.0/jre/../lib/amd64* :/opt/Oracle/Middleware11g/patch_wls1036/profiles/default/native:/opt/Oracle/Middleware11g/patch_ocp371/profiles/default/native:/opt/Oracle/Middleware11g/wlserver_10.3/server/native/linux/x86_64:/opt/Oracle/Middleware11g/wlserver_10.3/server/native/linux/x86_64/oci920_8 -D *java.class.path* =/opt/Oracle/Middleware11g/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/opt/Oracle/Middleware11g/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar:*/opt/Oracle/java/jrmc-4.0.1-1.6.0/lib/tools.jar*:/opt/Oracle/Middleware11g/wlserver_10.3/server/lib/weblogic_sp.jar:/opt/Oracle/Middleware11g/wlserver_10.3/server/lib/weblogic.jar:/opt/Oracle/Middleware11g/modules/features/weblogic.server.modules_10.3.6.0.jar:/opt/Oracle/Middleware11g/wlserver_10.3/server/lib/webservices.jar:/opt/Oracle/Middleware11g/modules/org.apache.ant_1.7.1/lib/ant-all.jar:/opt/Oracle/Middleware11g/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar::/opt/Oracle/Middleware11g -Dweblogic.system.BootIdentityFile=/opt/Oracle/Middleware11g/user_projects/domains/base_domain/servers/server-2/data/nodemanager/boot.properties -Dweblogic.nodemanager.ServiceEnabled=true -Dweblogic.security.SSL.ignoreHostnameVerification=false -Dweblogic.ReverseDNSAllowed=false -server -d64 -Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m weblogic.Server"
    As you can see above, the server process are still using java.class.path and java.library.path with references to Oracle JRockit JVM.
    I've tested in x86_64 and Sun SPARC platform. On x86_64 the server starts with no problem. But on Solaris SPARC the server crashs during startup time.
    So, my question is: how can we solve this? Are the Node Manager using setDomainEnv.sh or commEnv.sh vars to set the java.class.path and java.library.path opitons?
    Thanks.
    [1] http://docs.oracle.com/cd/E23943_01/web.1111/e13708/overview.htm

    Hi,
    You can use a different JVM for specific managed server by editing parameters in server start tab from console. But if you want to change java.class.path and java.library.path with references from Oracle JRockit JVM to JDK hotspot, then you have to create separate commonenv.sh,setdomainenv.sh and startWeblogic.sh file for your managed server.
    java.class.path and java.library.path env variables generally generates from commonenv.sh file.
    Regards,
    Kishore

  • Communication between different JVMs

    Hallo,
    is there a simple way, to exchange data between different java sessions? At the moment I store the needed data to a table and load it in my java procedures when ever I need them.
    But because this data is temporary, it wouldn't really be necessary to store the data. It's just for communication between the different JVMs. Is there an other way to do this, too?
    Thanks, Christian

    Christian, I may have misunderstood your question, but, until java version 1.4, the only way for different JVMs to communicate was via sockets, or secondary storage (the file system -- which includes databases).
    In java version 5.0 (previously version 1.5), there is a new feature known as class data sharing.
    But since you posted to the "Database >> JVM" forum, I can't help thinking that you are referring to different database JVMs. Is that correct? In any case, sockets and secondary storage are your only options there as well.
    Good Luck,
    Avi.

  • How do i run two threads with different sleep times?

    How do i run two threads with different sleep times?
    Ive got thread A and thread B, they both update a jpanel.
    They both start when i press the start button.
    However thread A updates every 250ms and thread B updates every 1000ms. i cant just run them both at 250ms becuase this will mess it up.
    So for every four runs of thread A i want thread b to only be run once
    Does anyone know how to do this?
    Thanks, Ant...

    ok, ive done it but now i cant stop it!
    ive added buttons to start and stop, the start button works but the stop button doesnt. why doesnt "t.stop();" work?
        public void run() {
            while(t == Thread.currentThread()) {
                System.out.println("No " + t.getName());
                if (t.getName().equals("1")){
                    try {
                        t.sleep(1000); // in milliseconds
                    } catch (InterruptedException e) {}
                } else{
                    try {
                        t.sleep(250); // in milliseconds
                    } catch (InterruptedException e) {}
        }

  • Thread running in jvm or os

    pls tell me thread running in jvm or operating system

    pls tell me thread running in jvm or operating systemIIRC, unless you are using a very old JVM (e.g. pre 1.2) or are explicitly specifying green threads (which I believe was still possible even in 1.2?) then all threading using native threads. As mentioned above, the mapping between Java thread objects and the native threads is is highly dependent on the OS (especially when it comes to thread priority).
    This document goes into much more detail: http://java.sun.com/docs/hotspot/threads/threads.html
    - N

  • Threading two different text boxes

    Hi.. How do you thread two different text box with two different text format?
    Eg. Text Box 1: Font Size 50pt...
    Text box 2: Font Size 10pt..
    Once you thread the two text boxes; and delete the content in Text box 1, what ever the content that flows to Text box 1 from text box 2 should auto format to Font Size 50.
    Any Idea how to do this?

    If I understand you corrrectly, I don't know how to do that, but in case I don't understand what you want, can you please tell me if I have this right?
    You have a chain of text frames. When you start entering text, it is 50pt. When the text fills the frame and jumps to the next frame, all of that text is 10pt. and this is all done automatically. In other words, the first word of the second frame would change from 10 to 50 automatically if it jumped back to the first frame for some reason (like the first frame being made larger, or some of it's text being deleted).
    If that's what you want, then maybe someone else knows how to do it, but I don't.

  • Monitor thread stacks in JVM

    Hi,
    I've a problem with my app, when my server runs for a long time, the memory used by the java process increases.
    I investigate this : the use of the heap seems to be good (no memory leak), i've used pmap for retreiving the use of memory by my process and i've seen that the number of range of memory reserved for [anon] increases (about 520K each times).
    I think that it is thread stack reserved but not freed.
    My question is : How can i link a memory address reservation with a thread (if it's possible) ??
    I use a JDK 1.5.0_10 un der RedHat Enterprise 3 Updt 4.
    Thanks

    pls tell me thread running in jvm or operating systemIIRC, unless you are using a very old JVM (e.g. pre 1.2) or are explicitly specifying green threads (which I believe was still possible even in 1.2?) then all threading using native threads. As mentioned above, the mapping between Java thread objects and the native threads is is highly dependent on the OS (especially when it comes to thread priority).
    This document goes into much more detail: http://java.sun.com/docs/hotspot/threads/threads.html
    - N

  • How to share Singleton in different JVM?

    How to share Singleton in different JVM?
    Suppose we have two application installed at different server, how to share the same Singleton?
    Rakesh

    You could use the sun game server's persistence mechanism. That would work, at possibly too great an expense than technically needed to make a shared singleton.
    ~Cheers

  • Serialization on different JVMs

    Hi,
    I was wondering, if I serialize an object on one JVM, will it deserialize correctly on a different JVM?
    For example, if I serialize an object using Sun's JDK, will it deserialize correctly on, say, GNU Classpath?
    Thanks

    Be careful to check the class API documentation as some classes carry a warning:
    Warning:  Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM  has been added to the java.beans package. Please see XMLEncoder.

  • FLEX working with a different JVM...?

    Hey I need help for this, because I don't know how to do it.
    My flex builder 2 is working with a different jvm than the one
    installed on my pc. The one I installed is JVM 1.5 and the one that
    Flex Builder 2 is using is JVM 1.4, and I've been having really big
    problems when launching it, and I think this might be the problem,
    so i would really appreciate if someone could tell me how to make
    FLEX Builder 2 work with JVM 1.5 (which is the one I
    installed).

    open jvm.config
    and set java.home to the path where the JVM you want to use
    is

  • Interfacing different JVM version

    hello gurus,
    quick question....
    Will different JVM versions running concurrently will interfere with each other ( eg. mouse events, etc).
    any response appreciated...thanks...@

    No,
    Each VM is it's own little world. There would be no interaction between them unless you specically wanted it. Even in that case GUI would behave as they should in each version.
    Hope this helps.

  • Thread problem or jvm problem?

    Hello, I've posted message on this link and now I've finished my project. Now, I have a different problem: that's why I'm posting this message here.
    if you want me to post my project code, I can , but I think it's not necessary for now... So, there are 5 classes; Main, Thread1 extends Thread, thread2 extends Thread, Thread3 extends Thread and ThreadFactory... in main method; factory instance is called for the creation of threads; so in main three type of thread instance created by factory. And right after that threads starts running and thread1 finished first, thread2 finished second, and thred3 finished third; However, the program itself never ends. There is a problem with thread endings. I've also make dubugging. Main thread creates the three of them and first main thread finishes second thread1 and the other three never finishes... keeps running.
    when main thread end it's state becomes zombie and thread1 also becomes zombie tooo.... but the other 2 of them never ends. I've tried may� things to do that: I've used finalyze() method too. Nothing chanced.
    I guessed that this may happen becouse of JVM... so what do you suggest for ending threads in a sequence like thread1, thread2, thread3, main?

    no help?

Maybe you are looking for

  • SAP Data Migration Framework

    Dear All, I read from TechEd that SAP data migration framework involves using Business Objects data services. SAP has provided pre-built Jobs with iDOC as target. All is fine but I came to know that we can use Data services as staging area and modify

  • Scanner Presets - Adobe Acrobat 9 Pro

    I removed a Canon CanoScan LiDE 60 from my Vista computer, drivers and all. The scanner continues to display in the Configure Presets Scanner Selection drop-down list. I have been unable to remove the uninstalled scanner from the list. Any help would

  • XBOX 360 with Apple Airport Express/AIrport Extreme?

    Well im about to buy an apple airport extreme wireless router for my house. The router is going to be located on the second floor with my cable modem. Planning to put my airport express in my room on the third floor. So i am just wondering if you can

  • Is there any documentation/notes for managing wrong transactions happend

    Hi Please let me know, is there any help/notes/documentation available for oracle apps 11i, which will help us to manage wrong data entries/transactions (already happened) that will affect costing/AP/AR/GL Postings. And provides some suggestions on h

  • (Solved) Missing .xinitrc (sorry for a newb thing)

    so I made the move from Ubuntu to Arch.  Happy so far and am going to just do a minimal install and use openbox stand alone.  I have openbox installed but on the wiki it says to append "exec openbox-session" to ~/.xinitrc which I can't seem to find.