本文整理汇总了Java中com.google.appengine.api.ThreadManager类的典型用法代码示例。如果您正苦于以下问题:Java ThreadManager类的具体用法?Java ThreadManager怎么用?Java ThreadManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThreadManager类属于com.google.appengine.api包,在下文中一共展示了ThreadManager类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
cl = getClass().getClassLoader();
Thread thread = ThreadManager.createBackgroundThread(new Runnable() {
@Override
public void run() {
Thread.currentThread().setContextClassLoader(cl);
doCleanup();
}
});
thread.start();
}
示例2: doGet
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
Thread thread = ThreadManager.createBackgroundThread(new Runnable() {
@Override
public void run() {
doCleanup();
}
});
thread.start();
}
开发者ID:GoogleCloudPlatform,项目名称:solutions-ios-push-notification-sample-backend-java,代码行数:13,代码来源:NotificationCleanupServlet.java
示例3: createClient
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Client createClient(String configServiceName)
throws GeneralSecurityException, IOException {
return new Client.Builder(configServiceName)
.setStatsLogFrequency(statsLogFrequency())
.setHttpTransport(UrlFetchTransport.getDefaultInstance())
.setFactory(ThreadManager.backgroundThreadFactory())
.build();
}
示例4: LoadMultipleParallel
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
public LoadMultipleParallel(final Collection<String> _ids, final DAO<E> _dao, final PropertyMeta _propertyMeta) {
super((_ids.size() / QUERY_PACK_SIZE) < 1 ? 1 : (_ids.size() / QUERY_PACK_SIZE), ThreadManager.currentRequestThreadFactory());
ids = new ArrayList<>(_ids);
result = new HashMap<>(_ids.size());
dao = _dao;
propertyMeta = _propertyMeta;
}
示例5: doGet
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
/**
* Create App Engine threads that will poll and the process the tasks.
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) {
for (int workerNo = 0; workerNo < NUMBER_OF_WORKERS; workerNo++) {
Thread thread = ThreadManager.createBackgroundThread(new Runnable() {
@Override
public void run() {
doPolling();
}
});
thread.start();
}
}
示例6: doGet
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
Thread thread = ThreadManager.createBackgroundThread(new Runnable() {
@Override
public void run() {
doCleanup();
}
});
thread.start();
}
示例7: doGet
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) {
// Create App Engine threads that will poll and the process the tasks.
for (int workerNo = 0; workerNo < NUMBER_OF_WORKERS; workerNo++) {
Thread thread = ThreadManager.createBackgroundThread(new Runnable() {
@Override
public void run() {
doPolling();
}
});
thread.start();
}
}
开发者ID:GoogleCloudPlatform,项目名称:solutions-ios-push-notification-sample-backend-java,代码行数:15,代码来源:PushNotificationWorkerServlet.java
示例8: start
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
/**
* Starts the websocket server, registers necessary information and then starts the bridge
* thread.
*/
public void start() {
if (chatSocketServer != null) {
throw new IllegalStateException("We already have a chatSocketServer.");
}
chatSocketServer = new ChatSocketServer(DEFAULT_PORT);
chatSocketServer.start();
LOG.info("Server started on port: " + chatSocketServer.getPort());
try {
registerWebSocketServerNode();
} catch (IOException e) {
LOG.warning(Throwables.getStackTraceAsString(e));
}
ThreadManager.createBackgroundThread(this).start();
}
示例9: doGet
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
System.out.println("*********************");
Logger.getRootLogger().removeAllAppenders();
BasicConfigurator.configure();
registerShutdownHook();
/* Load config */
try {
File configFile = new File(getServletContext().getRealPath(CONFIG_PATH));
Properties props = new Properties();
props.load(new FileReader(configFile));
props.load(new FileReader(configFile));
ProcessingQueue.getInstance().configure(props);
/* Start all processing threads */
for (Runnable runnable : ProcessingQueue.getInstance().getRunnables()) {
Thread thread = ThreadManager.createBackgroundThread(runnable);
thread.start();
}
} catch (Exception e) {
throw new IOException("Could not create processing threads", e);
}
logger.info("App started");
}
示例10: execute
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
@Override
public void execute(Runnable command) {
if(command != null){
ThreadFactory threadFactory = ThreadManager.backgroundThreadFactory();
ExecutorService service = Executors.newCachedThreadPool(threadFactory);
service.execute(command);
}
}
示例11: doGet
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
/**
* Call made from module when notification was added to task queue
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// super.doPost(req, resp);
if(counter == null){
counter = new SyncCounter();
}
/*
* Run a synced counter to work on polling in managed threads to deliver notifications as promptly as possible
*/
for (int workerNo = counter.value(); workerNo < MAX_WORKER_COUNT; workerNo++) {
// Get the current queue to check it's statistics
Queue notificationQueue = QueueFactory
.getQueue("notification-delivery");
if (notificationQueue.fetchStatistics().getNumTasks() > 30 * counter.value()) {
counter.increment();
cl = getClass().getClassLoader();
Thread thread = ThreadManager
.createBackgroundThread(new Runnable() {
public void run() {
Thread.currentThread().setContextClassLoader(cl);
try {
doPolling();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
} else {
break; // Current number of threads is sufficient.
}
}
resp.setStatus(HttpServletResponse.SC_OK);
}
示例12: applyAppEngineKludge
import com.google.appengine.api.ThreadManager; //导入依赖的package包/类
/**
* Overrides the threadFactory used in JSch and disable {@link Thread#setName(String)} in order to
* ensure GAE compatibility. By default it uses the default executor, which fails under GAE. This
* is currently a Google-specific patch that needs to be sent upstream.
*/
private static void applyAppEngineKludge() {
JSch.threadFactory = ThreadManager.currentRequestThreadFactory();
JSch.useThreadNames = false;
}