Results 1 to 5 of 5

Thread: checking if variable is blank after 20 seconds

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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?

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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?

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: checking if variable is blank after 20 seconds

    exactly
    "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
  •  



Click Here to Expand Forum to Full Width