• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Background thread

 
Nidheesh Puthalath
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can i run a background thread which has no connection with the MIDlet currently running?
let me explain the problem in more detail,

1. i am running a midlet(A) which will has the capability to download another midlet(B).
2. midlet A starts a thread(T1)
3. midlet A downloaded the jad and jar of midlet B and installs it.
4. midlet A launchs the midlet B.
5. midlet B is running now

what will happens to the thread T1 when B is running
will it be still in running state or is it destroyed immediatly after B gets the control?

Thanks in advance

Nidheesh.P
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If T1 falls out (returns from) its run method, it is gone and the JVM will clean it up. No different from J2SE.
Bill
 
Nidheesh Puthalath
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,

No, just consider an infinite while loop inside T1's run method. ie. T1 will run for ever. what will be the fate of T1 if some other thread(or main thread of midlet A) launchs midlet B.

Consider these code fragments also.

class A extends MIDlet implements Runnable
{
boolean exited = false;
public void run()
{
while(!exited)
{
...
}
}
public void someMethod()
{
Thread T1 = new Thread(this); //'this' is midlet A
T1.start();
}
}


what happens to T1 when A destroys.

in the above scenario (see the first post) what happens to A if I am launching B from A.

Eager to know the response from all

Nidheesh.P
Reliance Infocomm
Mumbai
India
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nidheesh P:
what happens to T1 when A destroys.


'A' is an application so if you kill its main all of its resources should be destroyed. If two application ran concurrently on the same JVM passing the thread may be possible but the CLDC spec says that there is no universal behavior for devices running J2ME applications concurrently:
Depending on the resources available on the device, a CLDC system can allow multiple Java applications to execute concurrently, or can restrict the system to permit only the execution of one Java application at a time. It is up to the particular CLDC implementation to decide if the execution of multiple Java applications is supported by utilizing the multitasking capabilities (if they exist) of the underlying host operating system, or by instantiating multiple logical virtual machines to run the concurrent Java applications.


I was also under the impression that the sandbox model of J2ME prevents J2ME applications from declaratively starting or stopping other applications. The spec does not mention this (that I could find), so I could be wrong on that particular detail.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nidheesh P,

Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You need a "real" last name. You can change it

here.

Thanks! and welcome to the JavaRanch!
 
Nidheesh Puthalath
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Michael, I done it.

Hi Mark,

I sent a reply yesterday but it seems not updated.
Anyway I will resend it again.

Ur reply clears my doubt regarding the background thread.
But I still have one more problem.

Consider the case here,
1.midlet A is running
2.runtime memory of A contains jad and jar files of midlet B in two byte arrays.
3.assume some native methods which allows the applications to install, launch and remove midlet and midlet suites by passing the jad and jar files.
4.midlet A uses launchMIDletsuite method for launching the midlet B by passing the jad and jar files.
5.what will be the state of A after B is launched. (running?, waiting?, destroyed?)
6.Whether B is a subset of A. ie. Will A gets control back after B is destroyed.
7.if not, is there any way to get the control back to A?

Thanks a lot for ur thought

Nidheesh.P
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your contrived scenario is going to be different device to device on how it would be handled. There is no set answer.

I am skeptical that you could really get yourself into such a scenario though, and if you really wanted such functionality you might as well program outside of J2ME, which inherently comes with various security restrictions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic