|
-
Jul 17th, 2008, 01:41 PM
#1
Thread Starter
Frenzied Member
checking if variable is blank after 20 seconds
Code:
public class Test {
public static void main(String[] args) {
long startTime = System.nanoTime();
String blah = "";
while(true) {
System.out.println("testing");
if (System.nanoTime() - startTime > 20000)
break;
}
}
}
i want to somehow check if blah.equals("") after 20 seconds, can anyone help me?
-
Jul 17th, 2008, 06:12 PM
#2
Re: checking if variable is blank after 20 seconds
Code:
public static void main(String[] args)
{
String blah = "";
Thread th = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
Thread.sleep(20000);
}
catch (InterruptedException e)
{
}
}
});
th.start();
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 17th, 2008, 06:13 PM
#3
Re: checking if variable is blank after 20 seconds
Of course it won't make any sense to do that for a local variable
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 18th, 2008, 03:57 AM
#4
Thread Starter
Frenzied Member
Re: checking if variable is blank after 20 seconds
Thanks ComputerJy, but where would i check to see if blah still is "" after 20 seconds? after the Thread.sleep line?
-
Jul 18th, 2008, 04:13 AM
#5
Re: checking if variable is blank after 20 seconds
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|