Java1 5新特性。Executors的一些用法

2021-06-18 08:51:24 字數 2682 閱讀 8002

執行緒池---excutors的用法

返回型別 

方法 

static callablecallable(privilegedaction action)

返回 callable 物件,呼叫它時可執行給定特權的操作並返回其結果。

static callablecallable(privilegedexceptionaction action) 

返回 callable 物件,呼叫它時可執行給定特權的異常操作並返回其結果。

static callablecallable(runnable task) 

返回 callable 物件,呼叫它時可執行給定的任務並返回 null。

static callablecallable(runnable task, t result) 

返回 callable 物件,呼叫它時可執行給定的任務並返回給定的結果。

static threadfactory   

defaultthreadfactory() 

返回用於建立新執行緒的預設執行緒工廠。

static executorservice   newcachedthreadpool() 

建立乙個可根據需要建立新執行緒的執行緒池,但是在以前構造的執行緒可用時將重用它們。

static executorservice   newcachedthreadpool(threadfactory threadfactory) 

建立乙個可根據需要建立新執行緒的執行緒池,但是在以前構造的執行緒可用時將重用它們,並在需要時使用提供的 threadfactory 建立新執行緒。

static executorservice   newfixedthreadpool(int nthreads) 

建立乙個可重用固定執行緒集合的執行緒池,以共享的無界佇列方式來執行這些執行緒。

static executorservice   newfixedthreadpool(int nthreads, threadfactory threadfactory) 

建立乙個可重用固定執行緒集合的執行緒池,以共享的無界佇列方式來執行這些執行緒,在需要時使用提供的 threadfactory 建立新執行緒。

static scheduledexecutorservice     newscheduledthreadpool(int corepoolsize) 

建立乙個執行緒池,它可安排在給定延遲後執行命令或者定期地執行。

static scheduledexecutorservice     newscheduledthreadpool(int corepoolsize, threadfactory threadfactory) 

建立乙個執行緒池,它可安排在給定延遲後執行命令或者定期地執行。

static executorservice  

newsinglethreadexecutor() 

建立乙個使用單個 worker 執行緒的 executor,以無界佇列方式來執行該執行緒。

static executorservice   

newsinglethreadexecutor(threadfactory threadfactory) 

建立乙個使用單個 worker 執行緒的 executor,以無界佇列方式來執行該執行緒,並在需要時使用提供的 threadfactory 建立新執行緒。

static scheduledexecutorservice     newsinglethreadscheduledexecutor() 

建立乙個單執行緒執行程式,它可安排在給定延遲後執行命令或者定期地執行。

static scheduledexecutorservice          newsinglethreadscheduledexecutor(threadfactory threadfactory) 

建立乙個單執行緒執行程式,它可安排在給定延遲後執行命令或者定期地執行。

static callable

privilegedcallable(callablecallable) 

返回 callable 物件,呼叫它時可在當前的訪問控制上下文中執行給定的 callable 物件。

static callable

privilegedcallableusingcurrentclassloader(callablecallable) 

返回 callable 物件,呼叫它時可在當前的訪問控制上下文中,使用當前上下文類載入器作為上下文類載入器來執行給定的 callable 物件。

static threadfactory   

privilegedthreadfactory() 

返回用於建立新執行緒的執行緒工廠,這些新執行緒與當前執行緒具有相同的許可權。

static executorservice   

unconfigurableexecutorservice(executorservice executor) 

返回乙個將所有已定義的 executorservice 方法委託給指定執行程式的物件,但是使用強制轉換可能無法訪問其他方法。

static scheduledexecutorservice     unconfigurablescheduledexecutorservice(scheduledexecutorservice executor)

返回乙個將所有已定義的 executorservice 方法委託給指定執行程式的物件,但是使用強制轉換可能無法訪問其他方法。

JAVA1 5新特性 註解Annotation

public inte ce inherited string value value string 註解型別與介面的像是之處 註解型別是一種介面,但它又不同於介面,如何自定義註解型別 1 使用 inte ce關鍵字 2 使用註解時類似與public final這樣的修飾符。3 可用於修飾類 介面 ...

從頭認識java 1 5 繼承(2)

接著上一章節,我們來繼續介紹繼承。1.子類呼叫方法時的查詢方法的順序 package com.ray.ch01 public class animal public void sleep package com.ray.ch01 public class bird extends animal pu...

Java 新特性 列舉

package cn.enum.robertchao public enum color1 可以通過 列舉.內容 的形式進行取值操作。2 輸出列舉中的全部內容,可以使用foreach完成。利用foreach把列舉型別中的內容全部取出。package cn.enum.robertchao public...