sleep() 为什么要用try catch,它什么情况会产生异常呢?

wren4255 2008-04-15 03:04:05
谢谢
...全文
663 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wren4255 2008-04-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 climing 的回复:]
sleep
public static void sleep(long millis)
throws InterruptedException在指定的毫秒数内让当前正在执行的线程休眠(暂停执行)。该线程不丢失任何监视器的所属权。

参数:
millis - 以毫秒为单位的休眠时间。
抛出:
InterruptedException - 如果另一个线程中断了当前线程。当抛出该异常时,当前线程的中断状态 被清除。


------------------------------------------------------…
[/Quote]
淡了的风 2008-04-15
  • 打赏
  • 举报
回复
sleep
public static void sleep(long millis)
throws InterruptedException在指定的毫秒数内让当前正在执行的线程休眠(暂停执行)。该线程不丢失任何监视器的所属权。

参数:
millis - 以毫秒为单位的休眠时间。
抛出:
InterruptedException - 如果另一个线程中断了当前线程。当抛出该异常时,当前线程的中断状态 被清除。


--------------------------------------------------------------------------------

sleep
public static void sleep(long millis,
int nanos)
throws InterruptedException在指定的毫秒数加指定的纳秒数内让当前正在执行的线程休眠(暂停执行)。该线程不丢失任何监视器的所属权。

参数:
millis - 以毫秒为单位的休眠时间。
nanos - 要休眠的另外 0-999999 纳秒。
抛出:
IllegalArgumentException - 如果 millis 值为负或 nanos 值不在 0-999999 范围内。
InterruptedException - 如果另一个线程中断了当前线程。当抛出该异常时,当前线程的中断状态 被清除。
宋玮-深圳 2008-04-15
  • 打赏
  • 举报
回复
@exception InterruptedException if any thread has interrupted
* the current thread. The <i>interrupted status</i> of the
* current thread is cleared when this exception is thrown.

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧