473,407 Members | 2,598 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,407 software developers and data experts.

Unable to thread functionality

26
Hi

I'm trying out a simple threading application, wherein, I try to detect a list of Bluetooth users in the vicinity.

In its implementation, I've got a Swings form, which contains a 'Start' button and a TextArea.

On clicking 'Start', I look for the devices by calling a method detectData, which has an implementation of its own. When this happens, I ought to have a "Searching for devices..." message being screened on the TextArea. During this time, the 'Start' button is supposed to be disabled, I should be able to minimize the window, perform any other task on the machine and come back to it.

I've threaded the detectData() method. When this method done processing, it's supposed to show the found list in the TextArea.

The problem is, in the current implementation, the thread is eating up the entire functionality. I don't even get the "Searching for devices.." message on the textarea. I'm unable to close the window. Once the thread is done processing, things get back to normal, with the list shown and other functionality retained.

How do I fix this issue?

This is the code that I'm working with, as of now.

Expand|Select|Wrap|Line Numbers
  1. //This is the action listener for the Search button
  2.  
  3.     private void StartActionPerformed(java.awt.event.ActionEvent evt) 
  4.     {
  5.             Start.setEnabled(false);
  6.             Refresh.setEnabled(false);
  7.             TextArea.setText("Searching for Devices...\n");
  8.             t = new Thread(this, "Detect");
  9.             t.start();
  10.             try {
  11.                 t.join();
  12.             }
  13.             catch(Exception e){
  14.                 e.printStackTrace();
  15.             }
  16.  
  17.             if(detect_data.deviceCount <= 0) {
  18.                 TextArea.setText("No Devices Found");
  19.             }
  20.             else {
  21.                 TextArea.setText("Devices Found:\n");
  22.                 for (int i = 0; i <detect_data.deviceCount; i++) {
  23.                 TextArea.append(detect_data.Address[i]+" ("+detect_data.Name[i]+")\n");
  24.                 }
  25.  
  26.             Start.setEnabled(true);
  27.             Refresh.setEnabled(true);
  28.             }
  29. }
  30.  
  31.  
  32. //This is the Run() method
  33.  
  34. public void run() {
  35.         detect_data = new Main();
  36.         try {
  37.             detect_data.detect();
  38.         }
  39.         catch(Exception e)
  40.         {
  41.             //Catch exceptions
  42.         }
  43.     }
  44.  
Nov 28 '10 #1
1 1220
join()
Waits for this thread to die.
Dec 6 '10 #2

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

Similar topics

38
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.3.1 (final). Python 2.3.1 is a pure bug fix release of Python 2.3, released in...
3
by: Stephen Ferg | last post by:
I use the newsgroup mainly via my Web browser and Google. Over the last few days, when I click on a link to a thread, I've been frequently getting the message "Unable to find thread." Does...
28
by: dcrespo | last post by:
Hi all, How can I get a raised exception from other thread that is in an imported module? For example: --------------- programA.py ---------------
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
1
by: TRI_CODER | last post by:
I am trying to solve the following exception. The exception occurs when my ASP.NET code behind code attemtps to access a remore site using SSL. Please note that all certificates are valid and the...
7
by: Jed | last post by:
I am trying to open web project in VS 2003 using the File Share method. VS is running on XP Pro (Host) and I am accessing the root web of an XP Pro install on Virtual PC (Server) running on the...
0
by: bazzer | last post by:
hey, i am using visual basic.net 2003 and have an ASP.NET webform application thats accessing a microsoft access 2003 database. i kept getting the following error when i tried to run it: ERROR ...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
5
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.