VMThread.java

下载 VMThread.java
001 /**
002  * Copyright (C) 2007 The Android Open Source Project
003  *
004  * Licensed under the Apache License, Version 2.0 (the "License");
005  * you may not use this file except in compliance with the License.
006  * You may obtain a copy of the License at
007  *
008  *      http://www.apache.org/licenses/LICENSE-2.0
009  *
010  * Unless required by applicable law or agreed to in writing, software
011  * distributed under the License is distributed on an "AS IS" BASIS,
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  * See the License for the specific language governing permissions and
014  * limitations under the License.
015  */
016  
017 package java.lang;
018  
019 import java.util.logging.Logger;
020 import java.util.logging.Level;
021  
022 class VMThread
023 {
024     Thread thread;
025     int vmData;
026  
027     VMThread(Thread t) {
028         thread = t;
029     }
030  
031     native static void create(Thread t, long stacksize);
032  
033     static native Thread currentThread();
034     static native boolean interrupted();
035     static native void sleep (long msec, int nsec) throws InterruptedException;
036     static native void yield();
037  
038     native void interrupt();
039  
040     native boolean isInterrupted();
041  
042     /***
043      *  Starts the VMThread (and thus the Java Thread) with the given
044      *  stacksize.
045      *
046      * @param stacksize
047      *                 The desired stacksize.
048      */
049     void start(long stacksize) {
050         VMThread.create(thread, stacksize);
051     }
052  
053     private static final String UNSUPPORTED_THREAD_METHOD
054             "Deprecated Thread methods are not supported.";
055  
056     /***
057      * Suspends the Thread.
058      */
059     @SuppressWarnings("ThrowableInstanceNeverThrown")
060     void suspend() {
061         Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD,
062                 new UnsupportedOperationException());
063     }
064  
065     /***
066      * Resumes the Thread, assuming it is suspended.
067      */
068     @SuppressWarnings("ThrowableInstanceNeverThrown")
069     void resume() {
070         Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD,
071                 new UnsupportedOperationException());
072     }
073  
074     /***
075      * Queries whether this Thread holds a monitor lock on the
076      * given object.
077      */
078     native boolean holdsLock(Object object);
079  
080     /***
081      * Stops the Thread, passing it a Throwable (which might be ThreadDeath).
082      */
083     @SuppressWarnings("ThrowableInstanceNeverThrown")
084     void stop(Throwable throwable) {
085         Logger.global.log(Level.SEVERE, UNSUPPORTED_THREAD_METHOD,
086                 new UnsupportedOperationException());
087     }
088  
089     native void setPriority(int newPriority);
090     native int getStatus();
091  
092     /***
093      * Holds a mapping from native Thread statii to Java one. Required for
094      * translating back the result of getStatus().
095      */
096     static final Thread.State[] STATE_MAP = new Thread.State[] {
097         Thread.State.TERMINATED,     // ZOMBIE
098         Thread.State.RUNNABLE,       // RUNNING
099         Thread.State.TIMED_WAITING,  // TIMED_WAIT
100         Thread.State.BLOCKED,        // MONITOR
101         Thread.State.WAITING,        // WAIT
102         Thread.State.NEW,            // INITIALIZING
103         Thread.State.NEW,            // STARTING
104         Thread.State.RUNNABLE,       // NATIVE
105         Thread.State.WAITING         // VMWAIT
106     };
107  
108     /***
109      * Tell the VM that the thread's name has changed.  This is useful for
110      * DDMS, which would otherwise be oblivious to Thread.setName calls.
111      */
112     native void nameChanged(String newName);
113 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值