Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-20-2007, 09:29 AM
Member
 
Join Date: Dec 2007
Posts: 1
code453 is on a distinguished road
Any method for improving of java thread
Hello all,

I'm developing the java applet to received the numerical data from socket and then plot it with jfreechart. I used java thread to poll the socket via readline. This java applet contains in the Embedded Web server of Wiport (The Serial to WiFi Module). I've a problem of
1. Delayed of reading the data from socket which
when I turned the Wiport off (No power supplied). The applet still plot the graph if the data come so many.My data arrival rate to the applet is 57600 bps. My thread read period is thread.sleep(0,(int)read_period); (read_period = 50)
2. Are there any method to improve the speed of read the data ? or Any suggestion of my method?
3. Can socket wait with timeout? e.g. readline with timeout, read with timeout

My thread source code is here

Quote:
public void run() {

String s=null;

int i=0;

double min=0,max=0,data=0;



s = new String();

while(true){

while(connected){



// graph get data

try {

s = in.readLine();



data = Double.valueOf(s.trim()).doubleValue();

debugLabel.setText("" + data); // print received

if(data>=max) max = data;

if(data<=min) min = data;



// graph plot

if(duration>setduration){

// clear old data

for(int j=0; j<duration;j++)

dataset.getSeries(0).getDataItem(j).setY(0);



// set new duration

duration = setduration;



if(i>=duration) i = 0;

}



if(i>=duration){

if(setduration<=duration){

i=0;

// clear old data

for(int j=0; j<duration;j++)

dataset.getSeries(0).getDataItem(j).setY(0);



} else if(i >= setduration){

i=0;



// clear old data

for(int j=0; j<duration;j++)

dataset.getSeries(0).getDataItem(j).setY(0);



duration = setduration;

} else {

// plot in the case : new series period

series.add(i,data);

Yaxis.setRangeWithMargins(min,max);

dataset.getSeries(0).getDataItem(i).setY(data);

chartPanel.firePropertyChange("w",true,true);

chartPanel.repaint();

i++;

}

} else {

// plot in the case : update old series

Yaxis.setRangeWithMargins(min,max);

dataset.getSeries(0).getDataItem(i).setY(data);

chartPanel.firePropertyChange("a",true,true);

chartPanel.repaint();

i++;

}

} catch (IOException ex) {

ex.printStackTrace();

debugLabel.setText("Connection Timeout");

connected = false;

}





// read sampling period

try {

thread.sleep(0,(int)read_period);

} catch (InterruptedException ex) {

ex.printStackTrace();

}

}





if(!connected){

statusLabel.setText("Reconnecting");

try {

thread.sleep(0,5000);

} catch (InterruptedException ex) {

ex.printStackTrace();

}



initial();

}



}
If you want more information please tell me

Thank you in advanced
ukyo yagamura
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
data from the main/GUI thread to another runnin thread... cornercuttin Threads and Synchronization 2 04-23-2008 11:30 PM
How to use sleep method of the Thread class Java Tip java.lang 0 04-09-2008 07:42 PM
If JNI thread call the java object in another thread, it will crash. skaterxu Advanced Java 0 01-28-2008 08:02 AM
Creating a Thread (extending Java Thread Class) JavaForums Java Blogs 0 12-19-2007 10:31 AM
Local Variables for a static method - thread safe? mikeg1z Advanced Java 1 11-16-2007 02:06 AM


All times are GMT +3. The time now is 05:56 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org