threadpoolexecutor

Why Future thread doesn't work in background of application?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 02:41:06
问题 Today I found a wierd problem. What I want is to check server availability (Particularly SSL checking) once application started and display proper message if server is down. This process should work in background and user is able to navigate the app if server has problem (app can works offline). What I did is simple. In main activity I have @Override protected void onStart() { super.onStart(); // Check Internet connection // Check Location sensor // Check server accessibility BackendCheck

Execute two Runnables Android

风流意气都作罢 提交于 2019-12-13 17:40:32
问题 I'd like to make two Runnables work for my Android App: 1) Runnable r1 for changing an ImageView: Runnable r1 = new Runnable() { @Override public void run() { albumpic.setImageResource(pub[i]); i++; if(i >= pub.length) { i = 0; } albumpic.postDelayed(this, 3000); } }; albumpic.postDelayed(r1, 3000); 2) Runnable r2 for changing a TextView: Runnable r2 = new Runnable(){ @Override public void run(){ out = "Title: " + retriever.extractMetadata(ShoutCastMetadataRetriever.METADATA_KEY_TITLE) + "

fetching data in parallel [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-13 08:24:45
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I am developing an android application in which I want to integrate data(home timeline) from multiple social medias. Making API calls and getting response from each of them is bit time consuming if done in a serial fashion. So i want a parallel environment to make API calls to

cancel() not working while trying to cancel tasks in ThreadPoolExecutor Android

时光毁灭记忆、已成空白 提交于 2019-12-13 01:24:21
问题 I have a few downloads that are submitted as tasks to a ThreadPoolExecutor . Now, I am creating this ThreadPoolExecutor in a global class that extends Application . I am storing all the submitted tasks in a hashmap with ids. I have a list view in a fragment. This list view item contains pause and resume buttons. When I click on the list item itself, the download FutureTask is submitted to the global pool executor. Now, when I click on the pause button of the listview item, I want that

Android application is hanged and showing black screen for 5-6 seconds when checking if a server port is open or not using ThreadPoolExecutor

我的未来我决定 提交于 2019-12-13 00:12:43
问题 I need to run a service if a server port is open. I am doing this by using below method. public Future<Boolean> ifPortIsOpenThenStartIridiumService(final Context context, final String device_mac, final String device_imei, final String input_mobile) { return Executors.newFixedThreadPool(20).submit(new Callable<Boolean>() { @Override public Boolean call() { try { String SERVER_IP = "IP Address"; int SERVER_PORT = Server_port; int DURATION = 1000; Socket socket = new Socket(); socket.connect(new

Producer Consumer in Java using threads never terminates

半城伤御伤魂 提交于 2019-12-12 04:06:01
问题 I have a Producer-Consumer problem to implement in Java, where I want the producer thread to run for a specific amount of time e.g. 1 day, putting objects in a BlockingQueue -specifically tweets, streamed from Twitter Streaming API via Twitter4j- and the consumer thread to consume these objects from the queue and write them to file. I've used the PC logic from Read the 30Million user id's one by one from the big file, where producer is the FileTask and consumer is the CPUTask (check first

Handling exceptions from Java ExecutorService tasks

拥有回忆 提交于 2019-12-12 02:39:08
问题 I'm trying to use Java's ThreadPoolExecutor class to run a large number of heavy weight tasks with a fixed number of threads. Each of the tasks has many places during which it may fail due to exceptions. I've subclassed ThreadPoolExecutor and I've overridden the afterExecute method which is supposed to provide any uncaught exceptions encountered while running a task. However, I can't seem to make it work. For example: public class ThreadPoolErrors extends ThreadPoolExecutor { public

Java ExecutorService - scaling

隐身守侯 提交于 2019-12-11 10:47:37
问题 I am trying to write a program in Java using ExecutorService and its function invokeAll . My question is: does the invokeAll function solve the tasks simultaneously? I mean, if I have two processors, there will be two workers at the same time? Because aI can't make it scale correctly. It takes the same time to complete the problem if I give newFixedThreadPool(2) or 1. List<Future<PartialSolution>> list = new ArrayList<Future<PartialSolution>>(); Collection<Callable<PartialSolution>> tasks =

Java ThreadPoolExecutors idle thread shutdown - calling custom cleanup code

风格不统一 提交于 2019-12-11 09:59:18
问题 Per the ThreadPoolExecutor doc (Java ThreadPoolExecutor), if I create an executor service like so: new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); and when #threads > corePoolSize, idle threads will be killed. I wanted to call some application specific cleanup code when the ThreadPoolExecutor kills any thread. I wasn't able to get a clear way to do so. Appreciate any help. Thanks in advance. 回答1: the correct way to do this is by extending Thread and

ThreadPoolExecutor - Use threads before queue

瘦欲@ 提交于 2019-12-11 07:44:34
问题 I am replacing legacy thread pool with java given ThreadPoolExecutor. In legacy thread pool, 600 hundred threads are created on start up. But in ThreadPoolExecutor, using concept of core threads, max threads and prestartAllCoreThreads(), number of threads on start up can be limited. Now, 1) If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than queuing. 2 )If corePoolSize or more threads are running, the Executor always prefers queuing a