• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #405

16 Apr 2024 05:58AM UTC coverage: 0.0% (-88.9%) from 88.866%
#405

push

areyouok
add encoding to fix coverage report

0 of 5353 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jetcache-core/src/main/java/com/alicp/jetcache/support/JetCacheExecutor.java
1
package com.alicp.jetcache.support;
2

3
import java.util.concurrent.ScheduledExecutorService;
4
import java.util.concurrent.ScheduledThreadPoolExecutor;
5
import java.util.concurrent.ThreadFactory;
6
import java.util.concurrent.ThreadPoolExecutor;
7
import java.util.concurrent.atomic.AtomicInteger;
8
import java.util.concurrent.locks.ReentrantLock;
9

10
/**
11
 * Created on 2017/5/3.
12
 *
13
 * @author huangli
14
 */
15
public class JetCacheExecutor {
×
16
    protected volatile static ScheduledExecutorService defaultExecutor;
17
    protected volatile static ScheduledExecutorService heavyIOExecutor;
18
    private static final ReentrantLock reentrantLock = new ReentrantLock();
×
19

20
    private static AtomicInteger threadCount = new AtomicInteger(0);
×
21

22
    static {
23
        Runtime.getRuntime().addShutdownHook(new Thread() {
×
24
            @Override
25
            public void run() {
26
                if (defaultExecutor != null) {
×
27
                    defaultExecutor.shutdownNow();
×
28
                }
29
                if (heavyIOExecutor != null) {
×
30
                    heavyIOExecutor.shutdownNow();
×
31
                }
32
            }
×
33
        });
34
    }
×
35

36
    public static ScheduledExecutorService defaultExecutor() {
37
        if (defaultExecutor != null) {
×
38
            return defaultExecutor;
×
39
        }
40
        reentrantLock.lock();
×
41
        try{
42
            if (defaultExecutor == null) {
×
43
                ThreadFactory tf = r -> {
×
44
                    Thread t = new Thread(r, "JetCacheDefaultExecutor");
×
45
                    t.setDaemon(true);
×
46
                    return t;
×
47
                };
48
                defaultExecutor = new ScheduledThreadPoolExecutor(
×
49
                        1, tf, new ThreadPoolExecutor.DiscardPolicy());
50
            }
51
        }finally {
52
            reentrantLock.unlock();
×
53
        }
54
        return defaultExecutor;
×
55
    }
56

57
    public static ScheduledExecutorService heavyIOExecutor() {
58
        if (heavyIOExecutor != null) {
×
59
            return heavyIOExecutor;
×
60
        }
61
        reentrantLock.lock();
×
62
        try {
63
            if (heavyIOExecutor == null) {
×
64
                ThreadFactory tf = r -> {
×
65
                    Thread t = new Thread(r, "JetCacheHeavyIOExecutor" + threadCount.getAndIncrement());
×
66
                    t.setDaemon(true);
×
67
                    return t;
×
68
                };
69
                heavyIOExecutor = new ScheduledThreadPoolExecutor(
×
70
                        10, tf, new ThreadPoolExecutor.DiscardPolicy());
71
            }
72
        }finally {
73
            reentrantLock.unlock();
×
74
        }
75
        return heavyIOExecutor;
×
76
    }
77

78
    public static void setDefaultExecutor(ScheduledExecutorService executor) {
79
        JetCacheExecutor.defaultExecutor = executor;
×
80
    }
×
81

82
    public static void setHeavyIOExecutor(ScheduledExecutorService heavyIOExecutor) {
83
        JetCacheExecutor.heavyIOExecutor = heavyIOExecutor;
×
84
    }
×
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc