This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import info.ganglia.gmetric4j.gmetric.GMetric; | |
import info.ganglia.gmetric4j.gmetric.GMetricSlope; | |
import info.ganglia.gmetric4j.gmetric.GMetricType; | |
import info.ganglia.gmetric4j.gmetric.GangliaException; | |
import org.apache.commons.lang.StringUtils; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class MonitorUtil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daemonize yes | |
pidfile /var/run/redis.pid | |
port 6379 | |
timeout 300 | |
loglevel notice | |
logfile /opt/logs/redis/redis.log | |
databases 16 | |
save 900 1 | |
save 300 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.ellios.concurrency; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.Phaser; | |
/** | |
* Author: ellios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.ellios.concurrency; | |
import java.util.concurrent.BrokenBarrierException; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.CyclicBarrier; | |
public class BarrierDemo { | |
private static final int BATCH_SIZE = 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//看了恶俗的borrow,看到return就轻松多了, | |
//把对象置为空闲状态 | |
_factory.passivateObject(obj); | |
// Add instance to pool if there is room and it has passed validation | |
boolean doAllocate = false; | |
synchronized (this) { | |
if (isClosed()) { | |
//检查是否关闭 | |
shouldDestroy = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//将对对象的请求放入请求队列 | |
Latch latch = new Latch(); | |
_allocationQueue.add(latch); | |
//处理请求队列,三种情况。 | |
//1,池中有可用对象直接赋值给latch, | |
//2. 没有可用的对象,而且池中的对象数没有达到maxActive,latch的状态为可创建状态 | |
//3. 池子空,且达到最大的maxActive,返回。 | |
allocate(); | |
//处理情况三,大段的代码,有三种处理逻辑,主要介绍下WHEN_EXHAUSTED_BLOCK这种 | |
//先等待一段时间,如果在等待期间连接池仍然处于满负荷状态的话进行处理 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DBCPDemo { | |
public static void main(String[] args) throws SQLException { | |
System.out.println("Setting up data source."); | |
DataSource dataSource = setupDataSource(); | |
System.out.println("Done."); | |
// | |
// Now, we can use JDBC DataSource as we normally would. | |
// |