A little bit about thread
A thread is a piece of task which is to be executed in parallel to another task executed by an application.
Example, Consider a text editor which performs auto save operation after some particular length of text is typed into it.
Now there are two tasks, first showing the text typed into the editor and second, performing auto save.
Since the two tasks should be executed in parallel, they are performed in different threads. If both operations are done on the same thread, then while the thread is busy saving, it could not perform the typing process and it will show a lag till the save operation completes.
How to create Thread ?
There are a couple of ways of creating a thread. (more…)
Let’s say I give you a decimal number say 3.5 and ask it to convert it into a fraction. You will quickly give me the answer as 7/2 and prompt “What’s the big deal in it”.
But if I ask you to convert it using a java program, then??? It won’t be too easy right.
Well, it is pretty much easy….Read on !!! (more…)
Suppose we want to do a task after fixed time interval such as creating a beep sound after 5 seconds or checking the connection status after every 5 seconds. This may be easily accomplished using Executor framework in java.
There is a class called
ScheduledThreadPoolExecutor which has the methods to perform such kind of scheduling. Let’s get down to code right away: (more…)
Loading a class more than once using java’s built in ClassLoader is not possible because:
Builtin ClassLoader always checks if a class has already been loaded. If it is, it simply does nothing and returns.
Hence to reload a class, you have to use your custom ClassLoader.
Code to reload a class using custom ClassLoader is as follows: (more…)