473,396 Members | 1,982 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,396 software developers and data experts.

how to timeout a command

Hi all,
I need to execute a command, a method of an object, which will run for an
uncertain amount of time. It could be a long time. So what I want to do is
if the command does not return , say , in two or three seconds, I would like
to terminate it and move on. Is there any way I can do something like that?
Thank you for your help.
Wai
Jul 17 '05 #1
1 2605
You better read about Threads.
Here is short example. It's not good enough for real application (because it
waits 2 seconds anyway)
but it's good for start.
public class Controller {

public static void main(String[] args) {
Executer ex=new Executer();
ex.setPriority(Thread.currentThread().getPriority( )-1);
ex.start();
try {
Thread.sleep(2000);
ex.enough();
} catch (InterruptedException e) {
}

System.out.println("Last step was "+ex.i);
}
}
public class Executer extends Thread{
public int i;
boolean notEnough=true;
public void run(){
System.out.println("Start execution :)");
for (i=0;notEnough&&i<1000000000;i++) System.out.println("execute "+i);
System.out.println("End execution :(");
}
public void enough(){
notEnough=false;
}
}
You have to read Threads by yourself.
So you will know about synchronization and can modify this code for better
results :)

Alex Kizub.

wai yung wrote:
Hi all,
I need to execute a command, a method of an object, which will run for an
uncertain amount of time. It could be a long time. So what I want to do is
if the command does not return , say , in two or three seconds, I would like
to terminate it and move on. Is there any way I can do something like that?
Thank you for your help.
Wai


Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Adrian Casey | last post by:
I have a python script which uses pexpect and I want to timeout (i.e. raise pexpect.TIMEOUT) if a long running command does not produce the output I am expecting. To simulate the 'long running...
4
by: Cath B | last post by:
I am pretty sure I am getting a command timeout when execute a SQL procedure that has an output parameter. The code below is in an asp page that is called using RSGetASPObject. I want to be able...
4
by: Stefano | last post by:
Hi everibody, it's the first time i post on this newsgroup. I'm Stefano from Milano, italy. I'm a beginners with Sql2000. My problem is this. I run a View using enterprise manager and after less...
5
by: Jason | last post by:
Hi all I get the following error when executing a rather intense stored procedure from an ASPX page. I have tried: - Increasing timeouts on IIS 5.0 (all areas that even mention timeout) - use...
0
by: bonita | last post by:
If I add the code for user to download the file (e.g. if(File.Exists(FILE_NAME)){......}), the ASP.NET will give the following timeout error: Timeout expired. The timeout period elapsed prior to...
22
by: pb648174 | last post by:
After executing osql from the command line via the Windows scheduled task interface, the following error is returned: "Timeout expired" The code in the sql is as follows: BACKUP Database...
6
by: michael sorens | last post by:
I have used the visual designer to create a series of DataGridViews populated from SQLServer data. A typical call is: myCountsTableAdapter.Fill(myDataSet.myCounts); My application actually...
1
by: kalpacx | last post by:
Hi All, I am a newbie to db2 database. Currently i am facing an issue which i know for sure that many would have faced and resolved. I am running 6 sql scripts concurrently against the db ...
1
by: Andrew Cooper | last post by:
I've got a report that is using an ObjectDataSource to populate its data. The problem is that the report takes longer than 30 seconds to generate so it times out. If I were using an SQLDataSource...
0
by: Andrew Cooper | last post by:
I posted this in the aspnet newsgroup but thought I might have more luck with an answer here. I'd really appreciate any help I can get. Thanks. I've got a report that is using an...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.