本文整理匯總了Java中java.lang.Thread.start方法的典型用法代碼示例。如果您正苦於以下問題:Java Thread.start方法的具體用法?Java Thread.start怎麽用?Java Thread.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.Thread
的用法示例。
在下文中一共展示了Thread.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: spawnProcess
import java.lang.Thread; //導入方法依賴的package包/類
/**
* Spawn an OS subprocess. Follows the Oracle-recommended method of
* using ProcessBuilder rather than Runtime.exec(), and includes some
* safeguards to prevent blocked and stale processes. A thread is
* created that will perform the spawn, consume its output and error
* streams (to prevent blocking due to full buffers), then clean up.
*
* @param cmd The cmd/arg list for execution
*/
static public void spawnProcess(final List<String> cmd) {
if (cmd == null)
return;
Thread t = new Thread() {
public void run() {
Process proc = null;
proc = startProcess(cmd, true);
if (proc != null) {
consumeProcessOutput(proc);
try {
proc.waitFor();
}
catch (InterruptedException e) {
// ignore (we terminate anyway)
}
destroyProcess(proc);
}
Thread.currentThread().interrupt();
}
};
t.setDaemon(true);
t.start();
}
示例2: instantiateIngest
import java.lang.Thread; //導入方法依賴的package包/類
/**
* Instantiates ingest thread for the current edits segment.
*/
private void instantiateIngest() throws IOException {
InjectionHandler.processEvent(InjectionEvent.STANDBY_INSTANTIATE_INGEST);
try {
synchronized (ingestStateLock) {
if (checkIngestState()) {
LOG.info("Standby: Ingest for txid: " + currentSegmentTxId
+ " is already running");
return;
}
assertState(StandbyIngestState.NOT_INGESTING);
ingest = new Ingest(this, fsnamesys, confg, currentSegmentTxId);
ingestThread = new Thread(ingest);
ingestThread.setName("Ingest_for_" + currentSegmentTxId);
ingestThread.start();
currentIngestState = StandbyIngestState.INGESTING_EDITS;
}
LOG.info("Standby: Instatiated ingest for txid: " + currentSegmentTxId);
} catch (IOException e) {
setIngestFailures(ingestFailures + 1);
currentIngestState = StandbyIngestState.NOT_INGESTING;
throw e;
}
}
示例3: tesTokenHandling
import java.lang.Thread; //導入方法依賴的package包/類
@Test
public void tesTokenHandling() {
try {
connection = Mockito.mock(WebSocket.class);
String result;
AuthenticationToken auth = new AuthenticationToken("[email protected]", "123");
JSONReader<AuthenticationToken> tokenReader = new JSONReader<AuthenticationToken>();
String t = tokenReader.JSONWriter(auth);
TokenHandler tok = new TokenHandler(auth, t, connection);
Thread x = new Thread(tok);
x.start();
assertTrue(x.isAlive());
Thread.sleep(1000);
assertFalse(x.isAlive());
}
catch (Exception e) {
}
}
示例4: CellController
import java.lang.Thread; //導入方法依賴的package包/類
public CellController(CellFunction evaluator){
setType(OutputTypes.kCell);
setBackground(Color.black);
this.setLayout(gbl1);
cf = evaluator;
cellPanel = new CellPanel(this,cf.initialF(),cf.getStrings(),cf.getDemarcations(), cf.getColorPalette());
cellPanel.setBackground(Color.black);
if(cf.getBreakInterval()==1) setPaused(true);
try {
jbInit();
addKeyListener(this);
}
catch(Exception e) {
e.printStackTrace();
}
numRuns = evaluator.getGeneration();
cellUpdater = new Thread(this);
cellUpdater.start();
}
示例5: main
import java.lang.Thread; //導入方法依賴的package包/類
public static void main(String[] args) {
// thrd 1
Thread thrd1 = new Thread() {
public void run() {
foo();
}
};
thrd1.start();
// thrd 2
Thread thrd2 = new Thread() {
public void run() {
bar();
}
};
thrd2.start();
}
示例6: main
import java.lang.Thread; //導入方法依賴的package包/類
public static void main(String[] args)
{
StringBuilder s = new StringBuilder("Hahaha");
// Notice: void run method are the same to both, but I overloaded it.
Thread t = new Thread(new threadAndRunnable(s)); // this calls void run method
t.start(); // by the Interface Runnable
(new threadAndRunnable()).start(); // this calls a Thread by class Thread()
for(int i=0; i < 10; i++) // And it, only repetely shows a message
{
System.out.println("tchau!");
try{Thread.sleep(90);}catch(InterruptedException e){}
}
}
示例7: startAudioOutput
import java.lang.Thread; //導入方法依賴的package包/類
public void startAudioOutput()
{
try {
lineOut = (SourceDataLine)AudioSystem.getMixer(currentMixer).getLine(infoOut);
if(standardLatency)
lineOut.open(format,bufferSize);
else
lineOut.open(format);
lineOut.start();
System.out.println("Buffersize: "+bufferSize+" / "+lineOut.getBufferSize());
} catch (Exception e) {
lineOut = null;
System.out.println("No audio output available. Use Audio Devices dialog to reconfigure.");
}
Thread thread = new Thread(this);
// thread.setPriority(Thread.MAX_PRIORITY);
thread.start();
}
示例8: GalleryDownloadManager
import java.lang.Thread; //導入方法依賴的package包/類
public GalleryDownloadManager(HentaiAtHomeClient client) {
this.client = client;
processedHHDLFiles = new ArrayList<File>();
pendingGalleries = new ArrayList<Gallery>();
lastTokenRequest = System.currentTimeMillis() + 3600060; // we wait until one hour after client start before we start requesting tokens, so the server has time to qualify the client. there's no point reducing this, as it's checked server-side.
try {
hhdldir = FileTools.checkAndCreateDir(new File("hathdl"));
downloadeddir = FileTools.checkAndCreateDir(new File("downloaded"));
} catch(java.io.IOException e) {
HentaiAtHomeClient.dieWithError(e);
}
myThread = new Thread(this);
myThread.start();
}
示例9: instantiateIngest
import java.lang.Thread; //導入方法依賴的package包/類
/**
* Instantiates ingest thread for the given edits file type
*
* @param type (EDITS, EDITS_NEW)
*/
private void instantiateIngest(IngestFile type)
throws IOException {
File edits;
InjectionHandler.processEvent(InjectionEvent.STANDBY_INSTANTIATE_INGEST);
synchronized (ingestStateLock) {
assertState(StandbyIngestState.NOT_INGESTING);
edits = getIngestFile(type);
// if the file does not exist,
// do not change the state
if (!edits.exists()
|| InjectionHandler
.falseCondition(InjectionEvent.STANDBY_EDITS_NOT_EXISTS, type)) {
return;
}
setCurrentIngestFile(edits);
ingest = new Ingest(this, fsnamesys, confg, edits);
ingestThread = new Thread(ingest);
ingestThread.start();
currentIngestState = type == IngestFile.EDITS
? StandbyIngestState.INGESTING_EDITS
: StandbyIngestState.INGESTING_EDITS_NEW;
}
LOG.info("Standby: Instantiated ingest for edits file: " + edits.getName());
}
示例10: ThreadWorker
import java.lang.Thread; //導入方法依賴的package包/類
public ThreadWorker(ThreadOwner owner)
{
this.owner = owner;
thread = new Thread(this);
thread.start();
}
示例11: checkServicesStatus
import java.lang.Thread; //導入方法依賴的package包/類
private static void checkServicesStatus() throws Exception{
ClusterNodes cns = new ClusterNodes( 5000);
Thread check = new Thread( cns);
try{
check.start();
}
catch( Exception e){
check.stop();
System.err.println( "Checking for cluster services status has been disable due to an exception!");
System.err.println( "Check the logs and the stderr for more info.");
}
}
示例12: Microwave
import java.lang.Thread; //導入方法依賴的package包/類
public Microwave()
{
lightOn = false;
powerTubeOn = false;
isDoorOpened = false;
isButtonPressed = false;
timer = new Timer();
setOperatingMicrowaveStateMachine(OperatingMicrowaveStateMachine.readyToCook);
queue = new MessageQueue();
removal=new Thread(this);
//start the thread of Microwave
removal.start();
}
示例13: ExternalSecurityLight
import java.lang.Thread; //導入方法依賴的package包/類
public ExternalSecurityLight()
{
ambientLight = false;
timer = new Timer(this);
// line 48 "SecurityLight.ump"
setExternalSecurityLightStateMachineNight(ExternalSecurityLightStateMachineNight.Null);
setExternalSecurityLightStateMachine(ExternalSecurityLightStateMachine.day);
removal=new Thread(this);
//start the thread of ExternalSecurityLight
removal.start();
}
示例14: main
import java.lang.Thread; //導入方法依賴的package包/類
public static void main(String[] args)
{
Thread t = new Thread()
{
public void run()
{
for(int i = 0; i < 10; i++){
try
{
System.out.println("This is thread t");
Thread.sleep(300);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
if(i == 3)
break;
}
}
};
t.start();
for(int i = 0; i < 2; i++)
{
}
}
示例15: crea_servicio
import java.lang.Thread; //導入方法依賴的package包/類
void crea_servicio(Intent intent) {
if ( !eclListo ) {
eclThread = new Thread(new Runnable() {
public void run() {
iniciaECL();
Looper.prepare();
mHandler =
new Handler() {
public void handleMessage(Message msg) {
Log.w(TAG, "msg: " + msg.obj);
Message msgResult = Message.obtain();
msgResult.obj =
eclexec("(crepl:execute-sexp " +
(String)msg.obj + ")");
eclexec("(crepl:write-line-to-file #P\"" +
Constants.FILE_ECL_STATE + "\"" +
"\"" + (String)msg.obj + "\")");
Log.w(TAG, "despues de eclExec:" + msgResult.obj);
sHandler.sendMessage(msgResult);
}
};
Message msgResult = Message.obtain();
msgResult.arg1 = Constants.ECL_INICIADO;
sHandler.sendMessage(msgResult);
Looper.loop();
}
public void exit() {
mHandler.getLooper().quit();
}
});
eclThread.start();
Toast.makeText(this, " ECLTopLevel created ", Toast.LENGTH_LONG).show();
} else {
Message msg = Message.obtain();
msg.obj = intent.getStringExtra("code");
Log.w(TAG, "sendMessage: " + (String)msg.obj);
mHandler.sendMessage(msg);
}
}