aspose file tools*
The moose likes Threads and Synchronization and the fly likes Thread Migration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread Migration" Watch "Thread Migration" New topic
Author

Thread Migration

feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
I would like to transfer a thread from one mobile device to another using J2ME . This is to continue its execution in case one device is stop running. Could you help me please ?
Thanks
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

What exactly do you mean by transferring a thread?


Swastik
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
I mean a thread running on one machine is stopped saved with its current state then migrated to another machine and resume running it from its saved state
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

To migrate a single thread, you will need to migrate the whole program -- along with any opened resources. Keep in mind that a thread can have access to all memory and resources of the JVM. So, the whole JVM will need to be suspended, and then resumed on the other machine (including any opened resources).

Quite frankly, I don't think it can be done. But these days, with virtualization, I would not be surprised if someone releases a product to "VMotion" between anything these days.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
You are thinking about the problem the wrong way.

You can create a Runnable object that is Serializable and transfer that. If you have saved the state of the process correctly, a new Thread can start executing the run() method on the new machine.

Thread objects are intimately tied to the JVM and operating system they are created on - it makes no sense to try to transfer one.

Bill
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
I heared it can be done for Java using JavaGo tool but I want to do it for J2ME. Could you guide me how to do it even if I want to submit the whole program.
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
Dear William Could you please explain more .Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Take what William said and do some research. You will need to make anything that needs to go to the other device Serializable. If you don't know what that is, or how to do it then you should read this as well as any Tutorials you can find. What you should do for practice is start your application running, serialize it, close it, start up a new VM, deserialize the old application, and continue running from where you left off. If you properly serialize things (and take care of those situations where serialization is not possible or practicle) then you should be able to do this any number of times.

Then it is just a matter of generating a protocol to move from one location to another. I am not familiar with J2ME so I don't know what the best method will be for that, but if it were me - once I was done with the above steps, I would then research what people are using for communicating binary data between J2ME applications. When I knew this I could use it to transfer the serialized classes from above from one device to another then run it.

As for JavaGo - Don't know what that is, if you have a reference you can point to then that would help - or if it has a tutorial/contact/forum resources that you might be able to use to get more targeted help on that product, then perhaps you should use them.


Steve
feda alshahwan
Ranch Hand

Joined: Jul 26, 2008
Posts: 170
the problem is that J2ME doesnot support serialization??
The site for JavaGo is http://homepage.mac.com/t.sekiguchi/javago/
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Ok, no serializing on J2ME will hurt you, but not kill you. You should understand the concepts - and be able to do it successfully in JavaSE. Then, when you know how it works in general you will have to roll your own. This sounds hard - and it probably is. The DataOutputStream and DataInputStream will be your friends. I did a quick google for J2ME Serialization and found a hand full of resources demonstrating how it can be done. But I wouldn't suggest doing it until you understand how Serialization works in general first (for example, try the built in serialization with different versions of JVMs on different machines).

It looks like JavaGo requires JavaSE serialization, so no, you can't use that on J2ME. It also looks like it hasn't been updated since 2005, so I wouldn't suggest using it on modern JVMs with JavaSE either.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread Migration