I came across a question of how to stop a Java thread. I suddenly felt about the stop and other methods in the Thread class. Then i slowly remembered that they are no longer available and they are deprecated.
Then i started searching in net. Then i found a solution(i was not known that time that it was an ancient technique). It said we have to keep a volatile flag variable and we can check the status in the run(). It sounded good to me.
But when i was reading till end of the document, i came across how to stop a thread in non-running situations (wait or sleep implemented thread, I/O blocked thread i.e. thread reading or writing files). In those situations we can use interrupt method to do it efectively.
Hmmm its been so long since i used threads in my application. I used thread last when i was developing my network file transfer application. The application came very well than i expected. It doesnt even needed any file/directory access permission. I used a special mechanism in it. In that i was using multithreaded server. That was the last time i used effectively. Sounds like i have to brush up core java a bit.
I came across concurrent package when reading about this interrupt method. Hope to write about it soon.
I noted many people getting confused with volatile and transient variables in java.
volatile variable is a kind of static variable which shares its value among the threads. To be precise, the value of a volatile variable can be shared among threads and can be simulataneusly accessed or modified.
transient variable is a used to restrict a field from being serialized.
This entry was posted
on Mar 28, 2008
at Friday, March 28, 2008
and is filed under
java
. You can follow any responses to this entry through the
comments feed
.
3 comments
Great blog...keep your good work for your blog and i hope can see more cool news soon, cya
March 29, 2008 at 10:17 AM
Thanks a ton gns2. I will update more soon. About some more tech and entertainment info
March 29, 2008 at 10:41 AM
Post a Comment
Flickr Photostream
குருதியில் பூக்கள் நனையும் போது உறவுகள் உறங்கலாமோ?
temp
Contributors
- Kishore
- Everybody struggles and overcomes them. Some i come across and the way i did it.