timeunit.html

来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 571 行 · 第 1/2 页

HTML
571
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_03) on Wed Nov 02 09:51:53 CST 2005 --><META http-equiv="Content-Type" content="text/html; charset=gb2312"><TITLE>TimeUnit (Java 2 Platform SE 5.0)</TITLE><META NAME="keywords" CONTENT="java.util.concurrent.TimeUnit class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){    parent.document.title="TimeUnit (Java 2 Platform SE 5.0)";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="跳过导航链接"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>概述</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>软件包</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>类</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/TimeUnit.html"><FONT CLASS="NavBarFont1"><B>使用</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>树</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>已过时</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>索引</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>帮助</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup>&nbsp;2&nbsp;Platform<br>Standard&nbsp;Ed. 5.0</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="TimeoutException.html" title="java.util.concurrent 中的类"><B>上一个类</B></A>&nbsp;&nbsp;下一个类</FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../../../index.html@java_2Futil_2Fconcurrent_2FTimeUnit.html" target="_top"><B>框架</B></A>  &nbsp;&nbsp;<A HREF="TimeUnit.html" target="_top"><B>无框架</B></A>  &nbsp;&nbsp;<SCRIPT type="text/javascript">  <!--  if(window==top) {    document.writeln('<A HREF="../../../allclasses-noframe.html"><B>所有类</B></A>');  }  //--></SCRIPT><NOSCRIPT>  <A HREF="../../../allclasses-noframe.html"><B>所有类</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  摘要:&nbsp;嵌套&nbsp;|&nbsp;<A HREF="#enum_constant_summary">枚举常量</A>&nbsp;|&nbsp;字段&nbsp;|&nbsp;<A HREF="#method_summary">方法</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">详细信息:&nbsp;<A HREF="#enum_constant_detail">枚举常量</A>&nbsp;|&nbsp;字段&nbsp;|&nbsp;<A HREF="#method_detail">方法</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.util.concurrent</FONT><BR>枚举 TimeUnit</H2><PRE><A HREF="../../lang/Object.html" title="java.lang 中的类">java.lang.Object</A>  <IMG SRC="../../../resources/inherit.gif" ALT="继承者 "><A HREF="../../lang/Enum.html" title="java.lang 中的类">java.lang.Enum</A>&lt;<A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&gt;      <IMG SRC="../../../resources/inherit.gif" ALT="继承者 "><B>java.util.concurrent.TimeUnit</B></PRE><DL><DT><B>所有已实现的接口:</B> <DD>java.io.Serializable, <A HREF="../../lang/Comparable.html" title="java.lang 中的接口">Comparable</A>&lt;<A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&gt;</DD></DL><HR><DL><DT><PRE>public enum <B>TimeUnit</B><DT>extends <A HREF="../../lang/Enum.html" title="java.lang 中的类">Enum</A>&lt;<A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&gt;</DL></PRE><P><tt>TimeUnit</tt> 表示给定单元粒度的时间段,它提供在这些单元中进行跨单元转换和执行计时及延迟操作的实用工具方法。<tt>TimeUnit</tt> 不维护时间信息,但是有助于组织和使用可能跨各种上下文单独维护的时间表示形式。<p><tt>TimeUnit</tt> 主要用于通知基于时间的方法如何解释给定的计时参数。例如,如果 <A HREF="locks/Lock.html" title="java.util.concurrent.locks 中的接口"><CODE>lock</CODE></A> 不可用,则以下代码将在 50 毫秒后超时: <pre>  Lock lock = ...;  if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ... </pre>而以下代码将在 50 秒后超时: <pre>  Lock lock = ...;  if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ... </pre>但是注意,不保证特定超时实现能够以与给定 <tt>TimeUnit</tt> 相同的粒度通知段。<P><P><DL><DT><B>从以下版本开始:</B></DT>  <DD>1.5</DD></DL><HR><P><!-- =========== ENUM CONSTANT SUMMARY =========== --><A NAME="enum_constant_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>枚举常量摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="TimeUnit.html#MICROSECONDS">MICROSECONDS</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="TimeUnit.html#MILLISECONDS">MILLISECONDS</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="TimeUnit.html#NANOSECONDS">NANOSECONDS</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="TimeUnit.html#SECONDS">SECONDS</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR></TABLE>&nbsp;<!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>方法摘要</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;long</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#convert(long, java.util.concurrent.TimeUnit)">convert</A></B>(long&nbsp;duration,        <A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>&nbsp;unit)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;将给定单元的时间段转换到此单元。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#sleep(long)">sleep</A></B>(long&nbsp;timeout)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用此单元执行 <tt>Thread.sleep</tt>.这是将时间参数转换为 <tt>Thread.sleep</tt> 方法所需格式的便捷方法。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#timedJoin(java.lang.Thread, long)">timedJoin</A></B>(<A HREF="../../lang/Thread.html" title="java.lang 中的类">Thread</A>&nbsp;thread,          long&nbsp;timeout)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用此时间单元执行计时的 <tt>Thread.join</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;void</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#timedWait(java.lang.Object, long)">timedWait</A></B>(<A HREF="../../lang/Object.html" title="java.lang 中的类">Object</A>&nbsp;obj,          long&nbsp;timeout)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用此时间单元执行计时的 <tt>Object.wait</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;long</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#toMicros(long)">toMicros</A></B>(long&nbsp;duration)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;等效于 <tt>MICROSECONDS.convert(duration, this)</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;long</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#toMillis(long)">toMillis</A></B>(long&nbsp;duration)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;等效于 <tt>MILLISECONDS.convert(duration, this)</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;long</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#toNanos(long)">toNanos</A></B>(long&nbsp;duration)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;等效于 <tt>NANOSECONDS.convert(duration, this)</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>&nbsp;long</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#toSeconds(long)">toSeconds</A></B>(long&nbsp;duration)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;等效于 <tt>SECONDS.convert(duration, this)</tt>。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;<A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A></CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#valueOf(java.lang.String)">valueOf</A></B>(<A HREF="../../lang/String.html" title="java.lang 中的类">String</A>&nbsp;name)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;返回带有指定名称的该类型的枚举常量。</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;<A HREF="TimeUnit.html" title="java.util.concurrent 中的枚举">TimeUnit</A>[]</CODE></FONT></TD><TD><CODE><B><A HREF="TimeUnit.html#values()">values</A></B>()</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;按照声明该枚举类型的常量的顺序,返回包含这些常量的数组。</TD></TR></TABLE>&nbsp;<A NAME="methods_inherited_from_class_java.lang.Enum"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TH ALIGN="left"><B>从类 java.lang.<A HREF="../../lang/Enum.html" title="java.lang 中的类">Enum</A> 继承的方法</B></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../lang/Enum.html#clone()">clone</A>, <A HREF="../../lang/Enum.html#compareTo(E)">compareTo</A>, <A HREF="../../lang/Enum.html#equals(java.lang.Object)">equals</A>, <A HREF="../../lang/Enum.html#getDeclaringClass()">getDeclaringClass</A>, <A HREF="../../lang/Enum.html#hashCode()">hashCode</A>, <A HREF="../../lang/Enum.html#name()">name</A>, <A HREF="../../lang/Enum.html#ordinal()">ordinal</A>, <A HREF="../../lang/Enum.html#toString()">toString</A>, <A HREF="../../lang/Enum.html#valueOf(java.lang.Class, java.lang.String)">valueOf</A></CODE></TD></TR></TABLE>&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TH ALIGN="left"><B>从类 java.lang.<A HREF="../../lang/Object.html" title="java.lang 中的类">Object</A> 继承的方法</B></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../lang/Object.html#finalize()">finalize</A>, <A HREF="../../lang/Object.html#getClass()">getClass</A>, <A HREF="../../lang/Object.html#notify()">notify</A>, <A HREF="../../lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../lang/Object.html#wait()">wait</A>, <A HREF="../../lang/Object.html#wait(long)">wait</A>, <A HREF="../../lang/Object.html#wait(long, int)">wait</A></CODE></TD></TR></TABLE>&nbsp;<P><!-- ============ ENUM CONSTANT DETAIL =========== --><A NAME="enum_constant_detail"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"><B>枚举常量详细信息</B></FONT></TH>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?