How to find that a thread is alive or not
Hi all,
I've create a thread to make a http request in every 10 second and get a string as the response from the server. Requesting process start on the window open. And also I can dispose the window, so my processing is not stop. That is exactly what I want to do.
Say after disposing the window I open it again. So the same thread start again while the first one is running. It messup my work. So I think of it. Every window open try to check that thread is alive or not. If alive stop the thread and start is again.
So I try this simply.
public boolean ThreadIsAlive(){
if(processThread.isAlive())
return true;
else
return false;
}If I found the thread true on the above code, I want to stop it. So I try this.
public void stop(){
processThread = null;
}I think up to now what I have done is ok. Then on the ActionListner I do this.
ActionListener actionListener = new ActionListener(){
public void actionPerformed(ActionEvent e){
if(appProcess.IsThreadAlive()){
appProcess.stop();
System.out.println("Main Dialog!");
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
MainDialog dialog = new MainDialog(new javax.swing.JFrame(), true);
dialog.setVisible(true);
};No compile error. But I got a runtime exception.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at mytrayicon.Processing.IsThreadAlive(Processing.java:82)
at mytrayicon.PanelRadarMain$3.actionPerformed(PanelRadarMain.java:73)
at java.awt.TrayIcon.processActionEvent(TrayIcon.java:750)
at java.awt.TrayIcon.processEvent(TrayIcon.java:708)
at java.awt.TrayIcon.dispatchEvent(TrayIcon.java:690)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Can anybody help me to solve this.
Thanks
ItsJava wrote:
Hi all,
I've create a thread to make a http request in every 10 second and get a string as the response from the server. Requesting process start on the window open. And also I can dispose the window, so my processing is not stop. That is exactly what I want to do.
Say after disposing the window I open it again. So the same thread start again while the first one is running. It messup my work. So I think of it. Every window open try to check that thread is alive or not. If alive stop the thread and start is again.
So I try this simply.
public boolean ThreadIsAlive(){
if(processThread.isAlive())
return true;
else
return false;
}If I found the thread true on the above code, I want to stop it. So I try this.
public void stop(){
processThread = null;
That does not "stop" the thread, it simply removes that reference to it.
>
I think up to now what I have done is ok. Then on the ActionListner I do this.
ActionListener actionListener = new ActionListener(){
public void actionPerformed(ActionEvent e){
if(appProcess.IsThreadAlive()){
appProcess.stop();
System.out.println("Main Dialog!");
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
MainDialog dialog = new MainDialog(new javax.swing.JFrame(), true);
dialog.setVisible(true);
};No compile error. But I got a runtime exception.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at mytrayicon.Processing.IsThreadAlive(Processing.java:82)
at mytrayicon.PanelRadarMain$3.actionPerformed(PanelRadarMain.java:73)
at java.awt.TrayIcon.processActionEvent(TrayIcon.java:750)
at java.awt.TrayIcon.processEvent(TrayIcon.java:708)
at java.awt.TrayIcon.dispatchEvent(TrayIcon.java:690)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
I'm sorry, but you set a reference to null, then attempt to derference it, and you wonder why you get an NPE?
>
Can anybody help me to solve this.
ThanksTo stop the thread, have a volatile variable that you can change the value of using a synchronized method, and have the thread
periodically check the value of this variable and stop itself when the value equals a specific value. That is one way to properly
stop the thread.
Similar Messages
-
How we find that value exists in block or not??
Hi All:
I am building form in 10 g enviornment. I want to know that at execution time, that value exists in block or not. Beacuse I want to execute query only at this time when no value in block. its a tab sheet form. When I enter value in block. And then go to other block. then the previous block value disappears( query executes). Please every body know. Help me . Thanks
AliYou could check the block query status?
v_status := get_block_property(<block_name>,STATUS);
From the help:
STATUS Returns the VARCHAR2 value NEW if the block contains only new records, CHANGED if the block contains at least one changed record, and QUERY if the block contains only valid records that have been retrieved from the database. -
How to find that reports are in use or not?
HI experts
I have some set of reports under one InfoArea
I want to know that any user is using them or not?
And if someone is using then I want to find date on which it was last used..
Can you please tell me??
Regards
SwatiHi Swathi,
You can only get this information if the query/ workbook is enabled for statistics logging in transaction RSDDSTAT.
If it is enabled you can goto table RSDDSTAT ( BW 3.5) or RSDDSTAT_OLAP( BI 7.0 ) to see the users who executed the query . These tables store all the information per query session and you will find more than one rows per session but you can find the information you want i.e. users executing a particular query / workbook.
Also Tcode: SU01 will give you all the user lists in the server.
Regards
Pcrao. -
How to find out Max threads count for Custom Work Manager??
Hi All,
How to find out Max threads count for Custom Work Manager??
I have created 1 WM & targeted it to a cluster of 2 MS. Later I created Max thread Constraint = 300 & assigned that to my WM.
I need to check how many threads maximum were created by my WM after lets say 1 completed day.
The idea behind that is to understand if .. 300 is enough or need to increase the same way as we do it for JDBC datasource like.. Active connections Max count.. etc.
Any Idea?
regards,
TanmayHi Ashish,
Thanks for your response.
The monitoring page that you are suggesting does not indicate the max thread count reached for a particular WM.
For example, If I have Sample WM with 300 Max Thread Constraint, is there a way for me to check how many threads have been used out of 300??
Any pointers in this regard are appreciated.
Thanks,
Tanmay -
How to find that a sales order for which there is delivery but no goods
Hi
How to find that a sales order for which there is delivery but no goods issue has been done i.e we have an open delivery for a sales order.
How in VBUK table can we find out with the sales order no .
Thanks in advancemake use of table VBFA.
Regards
Peram -
How I find my iPod touch 4g without Internet acces.because my iPod lost on a trip so how I find that?
you will have to use the old fashioned way, like if you lost a wallet or purse.
-
1...how to find that a function module belongs to normal function module or
Hi to all.........
1...how to find that a function module belongs to normal function module or remote enabled function module?
Thanks and regards,
K.Swaminath reddyHi Swaminath,
Go to Transaction SE37.
In The Remote enabled function module, in the Attribute tab radio Button "Remote Enabled module will be selected and in the Normal Function Module, Normal Function Module will be selected.
Regards,
Mukesh Kumar -
HOW TO FIND THAT MY MACBOOK PRO POWER CHANGER IS ORGINAL OR NOT .
WHERE TO FIND IT .They should both have an Apple logo on them.
Clinton -
How to find that 2 references are pointing to same obejct??
how to find that 2 references are pointing to same obejct??
i feel that hashCode and equals will not work as far as i understood from javadocI wnat to know above because i want to check if ps in
this loop is same object or on each iteration new
object is created
for (int i = 0; i < 10 ;i ++)
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1,i);
ps.executeUpdate();}
Here's a better question. Why in the world did you put that statement in the loop in the first place, unless the variable 'sql' is modified within? -
How to find that how many times listener is restarted using listener.log
How to find that how many times listener is restarted using listener.log
Kishor wrote:
OS =HP-UX
RDBMS=Version 8.1.7.4.0
i didn't find any line in listener.log file containing word "starting"
grep starting listener.log|wc -l
0Check when last time listener started, According to that search using that word.
Example:-
node1> cat listener.log|grep Started|wc -l
2
node1> Edited by: CKPT on Jan 28, 2012 9:49 PM -
I forgot my Email authentication how to find that ?
i forgot that in which email the are sending me my Email authentication so tell me how to find that ?
i also forgot my security questions
so kindly send me this problem solution in my email ********
<Email Edited by Host>Hi Ahmad,
Thank you for using Apple Support Communities.
To get help with Apple ID security issues please contact account security in your country by following the link below.
Apple ID: Contacting Apple for help with Apple ID account security - Apple Support
Take care,
Alex H. -
If we dont know the request no and program name how to find that program
hi gurus
can anyone suggest me
if we dont know the request no and program name how to find that program
thank you
regards
kals.Hi,
If u forget all the details It is very difficult to find, u have to remember at least some details regarding to that program.. for that
1.. goto SE80 give u r package name u will get all the programs which r u developed according to the discription u can get some idea which u want.. and
2... go to SE09 trcode.. display all tr numbers..here all trs are there what u developed, u can get some idea by looking the description of the tr numbers..
I hope so u can get at least some thing .
Thanks and Regards,
Surya -
How to find that which flat file is belongs to which application server?
How to find that which flat file is belongs to which application server?
Hi,
Search im www.sap-img.com, you will get most of answers.
Jogdand M B -
How to find out each Cell having Data or Not in Excel File by Using WDJ
Hi Friends,
I have one doubt on WDJ.
I have to Upload Excel File. Click on Upload Button in Excel file Data will move to One Bapi. This is I was done. But my Requirement is if any empty Cell in Excel That File not uploaded it display one error message Please upload Correct Excel File
How to find out each Cell having Data or Not in Excel File by Using WDJ. Please tell me.
By Using this Code I have Upload Excel File
InputStream text = null;
int temp = 0;
//wdComponentAPI.getMessageManager().reportSuccess("filePath Vijay:::");
try
File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());
FileOutputStream op = new FileOutputStream(file);
if (wdContext.currentContextElement().getResource()!= null)
text = wdContext.currentContextElement().getResource().read(false);
while((temp=text.read())!= -1)
op.write(temp);
op.flush();
op.close();
path = file.getAbsolutePath();
//wdComponentAPI.getMessageManager().reportSuccess("Path Name :::::"+path);
catch(Exception ex)
ex.printStackTrace();
But my Requirement is If excel having any Empty Cell that excel file not uploaded.How to do this...
Regards
Vijay KalluriHi my friend
I would like to share you some APACHE APi´s that i use when i have to read excel files in Web Dynpro.
JAR = poi-3.2-FINAL-20081019.jar
Some Example:
POIFSFileSystem fs;
HSSFWorkbook wb;
HSSFSheet sheet;
String myMexican_ValueFromExcelis = "";
try {
fs = new POIFSFileSystem(new FileInputStream();
// and select the cell "y"
cell = row.getCell( 0 );
myMexican_ValueFromExcelis = cell.getCellValue();
}cach(Exception e){
REgargds -
How to find whether remote database is up or not (connected via dblink)
Hi,
I am using dblink to connect Biz database from Dev database.(Biz, Dev - database names)
Running dbms job using the dblink from the Dev database to update data on Biz database...
Problem is dbms job should run if and only if the Biz database is up for which i created the dblink...
1) How to make sure or implement the check to find whether the Biz is database is up or not in Pl/sql or sql...
2) How to reschedule the dbms jobs once the database is up
pls suggest me how to find whether the database is up or not b4 running the dbms job?
Using- Oracle 10gThe only way to know whether the remote database is up (and whether the network between the two databases is up and whether the remote database's listener is up and whether the password configured in the database link is correct and whether the local TNS alias is correct, etc) would be to actually run a query against the remote database over the database link. In other words, the way to figure out whether the link is up is to let the job run and catch & handle exceptions when there are problems.
By default, a job scheduled via DBMS_JOB will automatically reschedule itself if there is an unhandled exception by geometrically backing off (it waits 1 minute after the first failure, 2 minutes after the second, 4, 8, 16, 32 minutes, etc until it's marked as broken after 16 failures). You could, of course, catch appropriate exceptions and handle them in a reasonable fashion and manually reschedule jobs at intervals that make more sense for your particular job.
Justin
Maybe you are looking for
-
Business Systems and Business Service - does any difference
Hi Experts, Could any one please guide me what is the difference between Business Systems and Business Service. Which situations we use Business Systems / Business Service. Does it have any performance issues? Why we are not configu
-
I run a mac air on a single user account but multiple people using it, which is ok for the situation. All have their accounts in the apple mail app. what is missing for me is a separate password to access the mail account. otherwise anyone can see an
-
Vb6,adodb with sql server 2008
hi for i am new to vb6 with sql server 2008. I have managed to create database named : Tuscan77 in project folder with all the necessary tables with primary and foreign keys in tables. I have done the same project in vb6 with adodb with ms access and
-
Does the iPhone support pre-paid phone cards?
Just debating whether I get an iPhone to replace both my iPod Touch and my phone. Does it support pre-paid calling cards like Bell's and the other phone companies?
-
Installing my 10.7 HD in new Macbook
I'll be swapping my current 7200rpm SATA HD into a new MacBook Pro and want to add in the upgraded apps like iPhoto coming with the new computer - as I'll be sticking the new HD into my old MacBook. My question: Can I just drag from the Applications