Skip to content

Commit feb8aae

Browse files
author
oleg-vyalyh
authored
Changed the version. (#481)
* Changed the version. * Start ThreadPoolService.
1 parent 54d80df commit feb8aae

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'signing'
55

66

77
group 'com.backendless'
8-
version '6.1.1'
8+
version '6.2.0'
99
archivesBaseName='backendless'
1010

1111

src/com/backendless/Backendless.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public final class Backendless
6464
{
6565
private static String url = "https://api.backendless.com";
6666
private static final boolean isAndroid = isAndroidEnvironment();
67+
// do not remove or change 'isCoderunner', because it is used in CodeRunner initialization process
6768
private static boolean isCodeRunner = false;
6869
private static final BackendlessPrefs prefs;
6970

@@ -222,8 +223,11 @@ public static void initApp( Object context, final String applicationId, final St
222223
}
223224

224225
if( isCodeRunner() )
226+
{
227+
ThreadPoolService.getPoolExecutor();
225228
return;
226-
229+
}
230+
227231
String userToken = UserTokenStorageFactory.instance().getStorage().get();
228232

229233
if( userToken != null && !userToken.equals( "" ) )

src/com/backendless/ThreadPoolService.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,55 @@
2020

2121
import java.util.concurrent.ExecutorService;
2222
import java.util.concurrent.Executors;
23+
import java.util.concurrent.LinkedBlockingQueue;
24+
import java.util.concurrent.ThreadFactory;
25+
import java.util.concurrent.ThreadPoolExecutor;
26+
import java.util.concurrent.TimeUnit;
27+
import java.util.concurrent.atomic.AtomicInteger;
28+
2329

2430
public class ThreadPoolService
2531
{
26-
private static volatile ExecutorService threadPoolExecutor;
27-
private final static int corePoolSize = 10;
32+
private final static ExecutorService threadPoolExecutor;
33+
private final static int MAX_THREAD_POOL_SIZE = 10;
2834

35+
static
36+
{
37+
if (Backendless.isCodeRunner())
38+
threadPoolExecutor = new ThreadPoolExecutor(0, MAX_THREAD_POOL_SIZE, 2, TimeUnit.SECONDS,
39+
new LinkedBlockingQueue<Runnable>(),
40+
new SimpleThreadFactory("BackendlessSDK_CR"));
41+
else
42+
threadPoolExecutor = new ThreadPoolExecutor(2, MAX_THREAD_POOL_SIZE, 60, TimeUnit.SECONDS,
43+
new LinkedBlockingQueue<Runnable>(),
44+
new SimpleThreadFactory("BackendlessSDK"));
45+
46+
}
47+
2948
public static ExecutorService getPoolExecutor()
3049
{
31-
if( threadPoolExecutor == null )
50+
return threadPoolExecutor;
51+
}
52+
53+
private static class SimpleThreadFactory implements ThreadFactory
54+
{
55+
private final ThreadFactory threadFactory = Executors.defaultThreadFactory();
56+
private final String threadNamePrefix;
57+
private final boolean isDaemon = true;
58+
private final AtomicInteger threadNumber = new AtomicInteger();
59+
60+
public SimpleThreadFactory( String poolName )
3261
{
33-
synchronized( ThreadPoolService.class )
34-
{
35-
if( threadPoolExecutor == null )
36-
threadPoolExecutor = Executors.newFixedThreadPool( corePoolSize );
37-
}
62+
this.threadNamePrefix = "pool-" + poolName + "-thread-";
63+
}
64+
65+
@Override
66+
public Thread newThread( Runnable r )
67+
{
68+
Thread t = threadFactory.newThread( r );
69+
t.setName( threadNamePrefix + threadNumber.getAndIncrement() );
70+
t.setDaemon( isDaemon );
71+
return t;
3872
}
39-
40-
return threadPoolExecutor;
4173
}
4274
}

0 commit comments

Comments
 (0)