Showing posts with label Errors. Show all posts
Showing posts with label Errors. Show all posts

Saturday, 21 March 2015

Interrupted Exception (Thread.sleep() )

In this post I am going to describe what is an Interrupted Exception is and another thing is why always we write thread.sleep function in try catch block.

A thread or java execution throws an interrupted exception whenever a thread is interrupted by another thread. There might be some other reason also but this is the most frequent reason for the InterruptedException.

Whenever we use Thread.sleep() function, we have to use it in try catch block because this function can throw an interrupted exception. If we will not provide a catch block for handling that exception it might give an error at running time. Because the sleeping thread might be interrupted by some other running thread.

So the code for using thread.sleep will be.

I am writing only main function.
Note: Do not forget to use throws InterruptedException in whichever function you are using Thread.sleep.

public static void main(String [] args) throws InterruptedException{
     try {

           Thread.sleep(1000);  // sleeping the thread for 1000 ms
     } catch( InterruptedException e){

            System.out.println("our thread is interrupted");
        }
  }



Monday, 22 December 2014

Error:Changes are not reflected in Code Blocks / Taking too long to show changes in code blocks

The first issue is that some time in windows while working on codes block Changes are not reflected even after closing the prior executable , compiling and running again. The Problem is that the prior executable is not properly closed.

Solution1:You have to go to Task Manager and find that executable and close it from task manager. Then compile the programme again and then run, Changes will be reflected. It worked for me. 


The second issue is that some time it takes two long to running a programme in codes block even after programme is just a small one. The issue is that Antivirus is scaning that executable for viruses. So it is taking too long to show response.

Solution2: Go to your antivirus's setting. Find the exception tab. And add the path where you are saving your programmes. So that antivirus will not check for viruses in that folder again and you will see result as fast as it should be.

I hope it helps..

If you are getting any other error in code blocks post it in comment. I will try to answer that.

Related Posts

Related Posts Plugin for WordPress, Blogger...