feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
67
jdkSrc/jdk8/com/sun/jmx/snmp/tasks/Task.java
Normal file
67
jdkSrc/jdk8/com/sun/jmx/snmp/tasks/Task.java
Normal file
@@ -0,0 +1,67 @@
|
||||
// NPCTE fix for bugId 4510777, esc 532372, MR October 2001
|
||||
// file Task.java created for this bug fix
|
||||
/*
|
||||
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.jmx.snmp.tasks;
|
||||
|
||||
/**
|
||||
* This interface is implemented by objects that can be executed
|
||||
* by a {@link com.sun.jmx.snmp.tasks.TaskServer}.
|
||||
* <p>A <code>Task</code> object implements two methods:
|
||||
* <ul><li><code>public void run(): </code> from
|
||||
* {@link java.lang.Runnable}</li>
|
||||
* <ul>This method is called by the {@link com.sun.jmx.snmp.tasks.TaskServer}
|
||||
* when the task is executed.</ul>
|
||||
* <li><code>public void cancel(): </code></li>
|
||||
* <ul>This method is called by the {@link com.sun.jmx.snmp.tasks.TaskServer}
|
||||
* if the <code>TaskServer</code> is stopped before the
|
||||
* <code>Task</code> is executed.</ul>
|
||||
* </ul>
|
||||
* An implementation of {@link com.sun.jmx.snmp.tasks.TaskServer} shall call
|
||||
* either <code>run()</code> or <code>cancel()</code>.
|
||||
* Whether the task is executed synchronously in the current
|
||||
* thread (when calling <code>TaskServer.submitTask()</code> or in a new
|
||||
* thread dedicated to the task, or in a daemon thread, depends on the
|
||||
* implementation of the <code>TaskServer</code> through which the task
|
||||
* is executed.
|
||||
* <p>The implementation of <code>Task</code> must not make any
|
||||
* assumption on the implementation of the <code>TaskServer</code> through
|
||||
* which it will be executed.
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
* @see com.sun.jmx.snmp.tasks.TaskServer
|
||||
*
|
||||
* @since 1.5
|
||||
**/
|
||||
public interface Task extends Runnable {
|
||||
/**
|
||||
* Cancel the submitted task.
|
||||
* The implementation of this method is Task-implementation dependent.
|
||||
* It could involve some message logging, or even call the run() method.
|
||||
* Note that only one of run() or cancel() will be called - and exactly
|
||||
* one.
|
||||
**/
|
||||
public void cancel();
|
||||
}
|
||||
57
jdkSrc/jdk8/com/sun/jmx/snmp/tasks/TaskServer.java
Normal file
57
jdkSrc/jdk8/com/sun/jmx/snmp/tasks/TaskServer.java
Normal file
@@ -0,0 +1,57 @@
|
||||
// NPCTE fix for bugId 4510777, esc 532372, MR October 2001
|
||||
// file TaskServer.java created for this bug fix
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.jmx.snmp.tasks;
|
||||
|
||||
/**
|
||||
* This interface is implemented by objects that are able to execute
|
||||
* tasks. Whether the task is executed in the client thread or in another
|
||||
* thread depends on the TaskServer implementation.
|
||||
*
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
* @see com.sun.jmx.snmp.tasks.Task
|
||||
*
|
||||
* @since 1.5
|
||||
**/
|
||||
public interface TaskServer {
|
||||
/**
|
||||
* Submit a task to be executed.
|
||||
* Once a task is submitted, it is guaranteed that either
|
||||
* {@link com.sun.jmx.snmp.tasks.Task#run() task.run()} or
|
||||
* {@link com.sun.jmx.snmp.tasks.Task#cancel() task.cancel()} will be called.
|
||||
* <p>Whether the task is executed in the client thread (e.g.
|
||||
* <code>public void submitTask(Task task) { task.run(); }</code>) or in
|
||||
* another thread (e.g. <code>
|
||||
* public void submitTask(Task task) { new Thrad(task).start(); }</code>)
|
||||
* depends on the TaskServer implementation.
|
||||
* @param task The task to be executed.
|
||||
**/
|
||||
public void submitTask(Task task);
|
||||
}
|
||||
246
jdkSrc/jdk8/com/sun/jmx/snmp/tasks/ThreadService.java
Normal file
246
jdkSrc/jdk8/com/sun/jmx/snmp/tasks/ThreadService.java
Normal file
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.jmx.snmp.tasks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.sun.jmx.snmp.tasks.Task;
|
||||
import com.sun.jmx.snmp.tasks.TaskServer;
|
||||
|
||||
/**
|
||||
* This class implements a {@link com.sun.jmx.snmp.tasks.TaskServer} over
|
||||
* a thread pool.
|
||||
* <p><b>This API is a Sun Microsystems internal API and is subject
|
||||
* to change without notice.</b></p>
|
||||
**/
|
||||
public class ThreadService implements TaskServer {
|
||||
|
||||
public ThreadService(int threadNumber) {
|
||||
if (threadNumber <= 0) {
|
||||
throw new IllegalArgumentException("The thread number should bigger than zero.");
|
||||
}
|
||||
|
||||
minThreads = threadNumber;
|
||||
threadList = new ExecutorThread[threadNumber];
|
||||
|
||||
priority = Thread.currentThread().getPriority();
|
||||
cloader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
}
|
||||
|
||||
// public methods
|
||||
// --------------
|
||||
|
||||
/**
|
||||
* Submit a task to be executed.
|
||||
* Once a task is submitted, it is guaranteed that either
|
||||
* {@link com.sun.jmx.snmp.tasks.Task#run() task.run()} or
|
||||
* {@link com.sun.jmx.snmp.tasks.Task#cancel() task.cancel()} will be called.
|
||||
* This implementation of TaskServer uses a thread pool to execute
|
||||
* the submitted tasks.
|
||||
* @param task The task to be executed.
|
||||
* @exception IllegalArgumentException if the submitted task is null.
|
||||
**/
|
||||
public void submitTask(Task task) throws IllegalArgumentException {
|
||||
submitTask((Runnable)task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a task to be executed.
|
||||
* This implementation of TaskServer uses a thread pool to execute
|
||||
* the submitted tasks.
|
||||
* @param task The task to be executed.
|
||||
* @exception IllegalArgumentException if the submitted task is null.
|
||||
**/
|
||||
public void submitTask(Runnable task) throws IllegalArgumentException {
|
||||
stateCheck();
|
||||
|
||||
if (task == null) {
|
||||
throw new IllegalArgumentException("No task specified.");
|
||||
}
|
||||
|
||||
synchronized(jobList) {
|
||||
jobList.add(jobList.size(), task);
|
||||
|
||||
jobList.notify();
|
||||
}
|
||||
|
||||
createThread();
|
||||
}
|
||||
|
||||
public Runnable removeTask(Runnable task) {
|
||||
stateCheck();
|
||||
|
||||
Runnable removed = null;
|
||||
synchronized(jobList) {
|
||||
int lg = jobList.indexOf(task);
|
||||
if (lg >= 0) {
|
||||
removed = jobList.remove(lg);
|
||||
}
|
||||
}
|
||||
if (removed != null && removed instanceof Task)
|
||||
((Task) removed).cancel();
|
||||
return removed;
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
stateCheck();
|
||||
|
||||
final Object[] jobs;
|
||||
synchronized(jobList) {
|
||||
jobs = jobList.toArray();
|
||||
jobList.clear();
|
||||
}
|
||||
final int len = jobs.length;
|
||||
for (int i=0; i<len ; i++) {
|
||||
final Object o = jobs[i];
|
||||
if (o!= null && o instanceof Task) ((Task)o).cancel();
|
||||
}
|
||||
}
|
||||
|
||||
// to terminate
|
||||
public void terminate() {
|
||||
|
||||
if (terminated == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
terminated = true;
|
||||
|
||||
synchronized(jobList) {
|
||||
jobList.notifyAll();
|
||||
}
|
||||
|
||||
removeAll();
|
||||
|
||||
for (int i=0; i<currThreds; i++) {
|
||||
try {
|
||||
threadList[i].interrupt();
|
||||
} catch (Exception e) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
threadList = null;
|
||||
}
|
||||
|
||||
// private classes
|
||||
// ---------------
|
||||
|
||||
// A thread used to execute jobs
|
||||
//
|
||||
private class ExecutorThread extends Thread {
|
||||
public ExecutorThread() {
|
||||
super(threadGroup, "ThreadService-"+counter++);
|
||||
setDaemon(true);
|
||||
|
||||
// init
|
||||
this.setPriority(priority);
|
||||
this.setContextClassLoader(cloader);
|
||||
|
||||
idle++;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
while(!terminated) {
|
||||
Runnable job = null;
|
||||
|
||||
synchronized(jobList) {
|
||||
if (jobList.size() > 0) {
|
||||
job = jobList.remove(0);
|
||||
if (jobList.size() > 0) {
|
||||
jobList.notify();
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
jobList.wait();
|
||||
} catch (InterruptedException ie) {
|
||||
// terminated ?
|
||||
} finally {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (job != null) {
|
||||
try {
|
||||
idle--;
|
||||
job.run();
|
||||
} catch (Exception e) {
|
||||
// TODO
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
idle++;
|
||||
}
|
||||
}
|
||||
|
||||
// re-init
|
||||
this.setPriority(priority);
|
||||
Thread.interrupted();
|
||||
this.setContextClassLoader(cloader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private methods
|
||||
private void stateCheck() throws IllegalStateException {
|
||||
if (terminated) {
|
||||
throw new IllegalStateException("The thread service has been terminated.");
|
||||
}
|
||||
}
|
||||
|
||||
private void createThread() {
|
||||
if (idle < 1) {
|
||||
synchronized(threadList) {
|
||||
if (jobList.size() > 0 && currThreds < minThreads) {
|
||||
ExecutorThread et = new ExecutorThread();
|
||||
et.start();
|
||||
threadList[currThreds++] = et;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// protected or private variables
|
||||
// ------------------------------
|
||||
private ArrayList<Runnable> jobList = new ArrayList<Runnable>(0);
|
||||
|
||||
private ExecutorThread[] threadList;
|
||||
private int minThreads = 1;
|
||||
private int currThreds = 0;
|
||||
private int idle = 0;
|
||||
|
||||
private boolean terminated = false;
|
||||
private int priority;
|
||||
private ThreadGroup threadGroup = new ThreadGroup("ThreadService");
|
||||
private ClassLoader cloader;
|
||||
|
||||
private static long counter = 0;
|
||||
|
||||
private int addedJobs = 1;
|
||||
private int doneJobs = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user