473,770 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

interrupted exception in sleep why?

hi

I am displaying a digital clock in an applet.I am using Thread.sleep
(1000) for
counting every second.This works fine some times but some times my
clock just slows down or give an interrupted exception .I am not
calling Thread.interrup t anywhere in my program. why is it happening?
how to fix the problem?

Anks
Jul 17 '05 #1
5 13979
I thought with applets they automatically
call stop() when they are scrolled off screen.
Also, it is a waste to call sleep(300), use
sleep(1000).

"-wiseguy" <no****@all.net > wrote in message news:Xn******** *************** **@216.65.98.9. ..
an*****@indiati mes.com (Anks) wrote in
news:23******** *************** ***@posting.goo gle.com:
hi

I am displaying a digital clock in an applet.I am using Thread.sleep
(1000) for
counting every second.This works fine some times but some times my
clock just slows down or give an interrupted exception .I am not
calling Thread.interrup t anywhere in my program. why is it happening?
how to fix the problem?

Anks


There are threads, other than those that you explicitly start, that run
anytime a JAVA VM is created. You have to trap and recover from
InterruptedExce ption exceptions whenever you use Thread.sleep().

Don't rely on the Thread.sleep(10 00) as a timer for keeping track of time.
It only says that your thread will sleep for a "minimum" of 1000ms.

Instead, use a Date object and sleep for less than one second, maybe 300ms,
before waking up and checking if the clock should be updated.

Don't forget to "stop" the applet when it is not visible...and restart when
it becomes visible again.



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

Jul 17 '05 #2
Not necessarily. It depends on the implementation of the
browser/sandbox. Certain versions of Netscape will let the Applet run
for 30 seconds and if it does not automatically stop, it will kill the
applet in an ungraceful manner.

Also, if your applet is very CPU intensive it is much nicer to respond
to the stop method so that the users' browsing experience is more
responsive when they leave your page.

-Misk

Phil wrote:
I thought with applets they automatically
call stop() when they are scrolled off screen.
Also, it is a waste to call sleep(300), use
sleep(1000).

"-wiseguy" <no****@all.net > wrote in message news:Xn******** *************** **@216.65.98.9. ..
an*****@india times.com (Anks) wrote in
news:23****** *************** *****@posting.g oogle.com:

hi

I am displaying a digital clock in an applet.I am using Thread.sleep
(1000) for
counting every second.This works fine some times but some times my
clock just slows down or give an interrupted exception .I am not
calling Thread.interrup t anywhere in my program. why is it happening?
how to fix the problem?

Anks


There are threads, other than those that you explicitly start, that run
anytime a JAVA VM is created. You have to trap and recover from
InterruptedEx ception exceptions whenever you use Thread.sleep().

Don't rely on the Thread.sleep(10 00) as a timer for keeping track of time.
It only says that your thread will sleep for a "minimum" of 1000ms.

Instead, use a Date object and sleep for less than one second, maybe 300ms,
before waking up and checking if the clock should be updated.

Don't forget to "stop" the applet when it is not visible...and restart when
it becomes visible again.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--


-


Jul 17 '05 #3
On 21 Aug 2003 00:28:41 -0700, an*****@indiati mes.com (Anks) two-finger
typed:
Hi
Thanks for your response but i still didn't got it completely.
You have asked to use date object but i did not find any such method
in date classes which ensures a sleep of specified time(1000ms).Ho w
can I use date objects in place of sleep.
Thanks

Anks
He meant that you use Thread.sleep() with a lower number in combination
with checking the date/time of the system to see if you need to update the
visual representation.

I would use System.currentT imeMillis() for faster more accurate
comparisons between the previous update and the next.

e.g. if you first update was done on 123456789 milliseconds, and after
System.sleep(25 0), it shows 123457500 (711 ms later), you can sleep another
289 ms before updating again.
"-wiseguy" <no****@all.net > wrote in message news:<Xn******* *************** ***@216.65.98.9 >...
an*****@indiati mes.com (Anks) wrote in
news:23******** *************** ***@posting.goo gle.com:
> hi
>
> I am displaying a digital clock in an applet.I am using Thread.sleep
> (1000) for
> counting every second.This works fine some times but some times my
> clock just slows down or give an interrupted exception .I am not
> calling Thread.interrup t anywhere in my program. why is it happening?
> how to fix the problem?
>
> Anks
>


There are threads, other than those that you explicitly start, that run
anytime a JAVA VM is created. You have to trap and recover from
InterruptedExce ption exceptions whenever you use Thread.sleep().

Don't rely on the Thread.sleep(10 00) as a timer for keeping track of time.
It only says that your thread will sleep for a "minimum" of 1000ms.

Here is the bit you should have read carefully:
Instead, use a Date object and sleep for less than one second, maybe 300ms,
before waking up and checking if the clock should be updated. Don't forget to "stop" the applet when it is not visible...and restartwhen
it becomes visible again.
In other words: put a check in your thread loop for a boolean variable:

boolean keepRunning = true ;
public void run() {
keepRunning = true // when starting at first
while(keepRunni ng) { // loop until stop() is called
// update clock
repaint(); // assuming that paint() does all the work
// wait for about one second - or use more sophisticated timing
try { Thread.sleep(10 00); } catch(Interrupt edException ix) { break;}
}
}

public void stop() {
keepRunning = false ;
}



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---


Cheers.
Jul 17 '05 #4
"Phil" <ry***@ieee.org > wrote in news:5mU0b.1579 30$cF.56387@rwc rnsc53:
I thought with applets they automatically
call stop() when they are scrolled off screen.
Also, it is a waste to call sleep(300), use
sleep(1000).


My mistake in how I eplxained it. I mean't to say to override the necessary
methods so that applet and its associated thread don't take up CPU time when
the thing isn't visible.

re: 1000ms...a delay of 1 second can mean that your display might
occasionally miss the display of a second every once in a while.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 17 '05 #5
Neomorph <ne******@nospa m.demon.co.uk> wrote in
news:sj******** *************** *********@4ax.c om:
On 21 Aug 2003 00:28:41 -0700, an*****@indiati mes.com (Anks) two-finger
typed:
Hi
Thanks for your response but i still didn't got it completely.
You have asked to use date object but i did not find any such method
in date classes which ensures a sleep of specified time(1000ms).Ho w
can I use date objects in place of sleep.
Thanks

Anks


He meant that you use Thread.sleep() with a lower number in combination
with checking the date/time of the system to see if you need to update the
visual representation.

I would use System.currentT imeMillis() for faster more accurate
comparisons between the previous update and the next.

e.g. if you first update was done on 123456789 milliseconds, and after
System.sleep(25 0), it shows 123457500 (711 ms later), you can sleep another
289 ms before updating again.

Actually I would just be lazy and update the display with the current time
(acquired from a new Date object) every time that the applet thread becomes
runnable again. creating and displaying a text clock a few times each second
certainly isn't going to bog down the machine...at least it shouldn't. :^)

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4583
by: Jakub Moscicki | last post by:
Hello, A small problem: I get a signal during a system call (from xmlrpclib -> httplib) and an exception "IOError: Interrupted system call" is raised (this is system dependant, on other machine it does not raise this exception). I have my own signal handler so I want to simply ignore this exception if it occures. But for a reason mysterious to me I cannot catch this exception in the main's program try block. Anybody knows what's...
0
1730
by: Sylwia | last post by:
Hi! I have implemented a Python services. It behaves as a supervisor for log files. If the space used by log files is bigger than a given upper limit, then it starts to delete log files until the space is less than a given lower limit. It checks the space every 1000 secs. After that it falls asleep. It is configured to start up automatically on system boot. Everything works ok except one thing ... :( The service should run even when I...
2
3763
by: Sylwia | last post by:
Hi! I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log files is bigger than a given upper limit, then it starts to delete log files until the space is less than a given
0
1551
by: Nazgul | last post by:
Hi! Sorry if I posted it twice... I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log files is bigger than a given upper limit, then it starts to delete log files until the space is less than a given lower limit. I configured the service to start up automatically on system boot. The script checks the space used by log files every 1000...
1
2761
by: José Joye | last post by:
When I unload my appdomain, I got the following exception: A blocking operation was interrupted by a call to WSACancelBlockingCall: ..... My appdomain uses remoting... From previous post, I know that I should call "RemotingServices.Disconnect" to close the remoting channel while unloading my appdomain. However, when I pass my object (say m_remote), there is an exception telling:
1
22803
by: Sagaert Johan | last post by:
Hi Ii have a simple server thread in an app that listens for connections, for some unclear reason an exception is thrown every now and then : 'A blocking operation was interrupted by a call to WSACancelBlockingCall ' Any suggestion why this may happen ? The Exception is thrown by the svr.AcceptTcpClient() method See source below.
7
22239
by: Marco | last post by:
Hello,every one, I meet a question: in my old script, I usually use os.popen2() to get info from standard unix(LinuX) program like ps,ifconfig... Now, I write a OO-based programme, I still use os.popen2( check whether mplayer still working via ps command ), but some things I got the following message: Traceback (most recent call last):
3
10560
by: arjan321 | last post by:
Hello all, I have a strange problem with the .NET serialPort class. When I write some data to the serialport, not all the data is immediately send: every once in a while, only ~50 characters of the 64 characters I'm sending gets send. Then, when I do a write() again, the data gets send. This is unacceptable behavior for my program.
1
2171
by: ashish | last post by:
Hi All, I wanted to know how to handle events like 'logoff' in the main thread so that any process which is being run by svcDoRun method of service does not get 'interrupted function call' exception. I am posting a very simple service program , and i want to know that is there a way to handle such interrupts without explicitly calling try except block over blocking calls. Here is the example which is getting interrupted exception at...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.