• 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/ObjectPool.java
1
package com.alicp.jetcache.support;
2

3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5

6
import java.util.concurrent.ArrayBlockingQueue;
7

8
/**
9
 * @Description
10
 * @author: zhangtong
11
 * @create: 2023/10/6 3:27 PM
12
 */
13
public class ObjectPool<T> {
14
        private final ArrayBlockingQueue<T> queue;
15
        private final int size;
16
        private final ObjectFactory<T> factory;
17
        private static final Logger logger = LoggerFactory.getLogger(ObjectPool.class);
×
18

19
        public ObjectPool(int size, ObjectFactory<T> factory) {
×
20
            this.size = size;
×
21
            this.factory = factory;
×
22
            queue = new ArrayBlockingQueue<>(size);
×
23
            for (int i = 0; i < size; i++) {
×
24
                queue.add(factory.create());
×
25
            }
26
            logger.debug("Init the object pool with size {}", size);
×
27
        }
×
28

29
        public T borrowObject() {
30
            T t = queue.poll();
×
31
            if(t == null) {
×
32
                logger.debug("The pool is not enough, create a new object");
×
33
                return factory.create();
×
34
            }
35
            return t;
×
36
        }
37

38
        public void returnObject(T obj) {
39
            if (obj == null) {
×
40
                return;
×
41
            }
42
            factory.reset(obj);
×
43
            queue.offer(obj);
×
44
        }
×
45

46
        public interface ObjectFactory<T> {
47
            T create();
48
            void reset(T obj);
49
        }
50
}
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