473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

WHy my emulator blocks even when I use thread?

108 100+
I am trying some thread tuts in J2me and camee across this code on the Net. Whan I run it, the emulator blocks... What is the use of the thread when the application still blocks...And How do I make this work?

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.io.IOException;
  3.  
  4. import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.midlet.MIDlet;
  5.  
  6. public class J2MEBackgroundProcessing extends MIDlet implements CommandListener { private Display display;
  7.  
  8. private Form form= new Form("Background Processing");
  9.  
  10. private Command exit = new Command("Exit", Command.EXIT, 1);
  11.  
  12. private Command start = new Command("Start", Command.SCREEN, 2);
  13.  
  14. public J2MEBackgroundProcessing() { display = Display.getDisplay(this); form.addCommand(exit); form.addCommand(start); form.setCommandListener(this); }
  15.  
  16. public void startApp() { display.setCurrent(form); }
  17.  
  18. public void pauseApp() { }
  19.  
  20. public void destroyApp(boolean unconditional) { }
  21.  
  22. public void commandAction(Command command, Displayable displayable) { if (command == exit) { destroyApp(false); notifyDestroyed(); } else if (command == start) { Process process = new Process(this); process.start(); } } }
  23.  
  24. class Process implements Runnable { private BackgroundProcessing MIDlet;
  25.  
  26. public Process(BackgroundProcessing MIDlet) { this.MIDlet = MIDlet; }
  27.  
  28. public void run() { try { transmit(); } catch (Exception error) { System.err.println(error.toString()); } }
  29.  
  30. public void start() { Thread thread = new Thread(this); try { thread.start(); } catch (Exception error) { } }
  31.  
  32. private void transmit() throws IOException { } }
  33.  
  34.  
Dec 8 '10 #1
2 1601
Expand|Select|Wrap|Line Numbers
  1.             Process process = new Process(this);
  2.             process.start();
  3.  
should be
Expand|Select|Wrap|Line Numbers
  1. new Thread(new Process(this)).start();
Then sort out the class functions to branch from run().
Dec 11 '10 #2
phpuser123
108 100+
Thanks it worked fine now
Dec 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bruce Bon | last post by:
The class below is intended to play a Sun audio file (.au) in the background while the main thread, which is servicing a GUI, continues without impact. It doesn't work. For a sound file that...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
3
by: Alan Silver | last post by:
Hello, I have some pages that are protected by forms authentication, and am adding code to the global.asax so that if someone tries to load (say) /order83.aspx, if they are logged in, it will...
2
by: Alan Silver | last post by:
Hello, I have a pair of radiobuttons on a form, used to select the type of search someone is to do... <asp:RadioButton ID="rdbLastNDays" Text="Show tips for the last" GroupName="rbgSearch"...
5
by: jheines | last post by:
I am trying to explain how cookies and sessions work in a class I teach, but I have hit a wall when it comes to the interaction between cookies and the state of the privacy settings in Internet...
5
by: Boki | last post by:
Hi All, When thread returns, that means the thread is closed ? What is the standard way to kill it ? threadA= null ; Thank you for advice! /* CODE BEGIN */
1
by: ketaki | last post by:
Hello, I am facing a problem. I have a application in C# (winforms) where I am giving an option to the user to add labels during runtime. But when the application is restarted the labels that are...
1
by: masaniparesh | last post by:
Hi, In my C# program i am termination thread by thread.Abort when times out occur. But i figured out that even after thread.Abort operation the thread is being alive for the random time. I have...
5
by: kveerareddy | last post by:
Hi experts, Technologies: Spring, AJAX, Google web tool kit Problem: Ideally when the user stops using a web page then after 30 minutes, if the user is trying to access any ting then the...
8
by: harvindersingh | last post by:
Hello guys I have some custom events in my application i.e. KeyPress such as full screen for pressing F11 and so on. Currently this works fine but only when the main form which is listening tot he...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.