Cleanup pool suspend/resume semaphore use, add unit test.
parent
560f6e402a
commit
855dbafb86
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013, 2014 Brett Wooldridge
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zaxxer.hikari.util;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* @author Brett Wooldridge
|
||||
*/
|
||||
public final class FauxSemaphore extends Semaphore
|
||||
{
|
||||
private static final long serialVersionUID = 7994006542758337519L;
|
||||
|
||||
public static final FauxSemaphore FAUX_SEMAPHORE = new FauxSemaphore();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public FauxSemaphore()
|
||||
{
|
||||
super(1);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void acquireUninterruptibly()
|
||||
{
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void acquireUninterruptibly(int permits)
|
||||
{
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void release(int permits)
|
||||
{
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void release()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2013, 2014 Brett Wooldridge
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zaxxer.hikari.util;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* This class implements a lock that can be used to suspend and resume the pool. It
|
||||
* also provides a faux implementation that is used when the feature is disabled that
|
||||
* hopefully gets fully "optimized away" by the JIT.
|
||||
*
|
||||
* @author Brett Wooldridge
|
||||
*/
|
||||
public class GlobalPoolLock
|
||||
{
|
||||
public static final GlobalPoolLock FAUX_LOCK = new GlobalPoolLock(false) {
|
||||
@Override
|
||||
public void acquire() {}
|
||||
|
||||
@Override
|
||||
public void release() {}
|
||||
|
||||
@Override
|
||||
public void suspend() {}
|
||||
|
||||
@Override
|
||||
public void resume() {}
|
||||
};
|
||||
|
||||
public static final GlobalPoolLock SUSPEND_RESUME_LOCK = new GlobalPoolLock(true);
|
||||
|
||||
private static final int MAX_PERMITS = 10000;
|
||||
private final Semaphore acquisitionSemaphore;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private GlobalPoolLock(final boolean createSemaphore) {
|
||||
acquisitionSemaphore = (createSemaphore ? new Semaphore(MAX_PERMITS, true) : null);
|
||||
}
|
||||
|
||||
public void acquire()
|
||||
{
|
||||
acquisitionSemaphore.acquireUninterruptibly();
|
||||
}
|
||||
|
||||
public void release()
|
||||
{
|
||||
acquisitionSemaphore.release();
|
||||
}
|
||||
|
||||
public void suspend()
|
||||
{
|
||||
acquisitionSemaphore.acquireUninterruptibly(MAX_PERMITS);
|
||||
}
|
||||
|
||||
public void resume()
|
||||
{
|
||||
acquisitionSemaphore.release(MAX_PERMITS);
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013, 2014 Brett Wooldridge
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zaxxer.hikari.util;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* @author Brett Wooldridge
|
||||
*/
|
||||
public final class FauxSemaphore extends Semaphore
|
||||
{
|
||||
private static final long serialVersionUID = 7994006542758337519L;
|
||||
|
||||
public static final FauxSemaphore FAUX_SEMAPHORE = new FauxSemaphore();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public FauxSemaphore()
|
||||
{
|
||||
super(1);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void acquireUninterruptibly()
|
||||
{
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void acquireUninterruptibly(int permits)
|
||||
{
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void release(int permits)
|
||||
{
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void release()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2013, 2014 Brett Wooldridge
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.zaxxer.hikari.util;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* This class implements a lock that can be used to suspend and resume the pool. It
|
||||
* also provides a faux implementation that is used when the feature is disabled that
|
||||
* hopefully gets fully "optimized away" by the JIT.
|
||||
*
|
||||
* @author Brett Wooldridge
|
||||
*/
|
||||
public class GlobalPoolLock
|
||||
{
|
||||
public static final GlobalPoolLock FAUX_LOCK = new GlobalPoolLock(false) {
|
||||
@Override
|
||||
public void acquire() {}
|
||||
|
||||
@Override
|
||||
public void release() {}
|
||||
|
||||
@Override
|
||||
public void suspend() {}
|
||||
|
||||
@Override
|
||||
public void resume() {}
|
||||
};
|
||||
|
||||
public static final GlobalPoolLock SUSPEND_RESUME_LOCK = new GlobalPoolLock(true);
|
||||
|
||||
private static final int MAX_PERMITS = 10000;
|
||||
private final Semaphore acquisitionSemaphore;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private GlobalPoolLock(final boolean createSemaphore) {
|
||||
acquisitionSemaphore = (createSemaphore ? new Semaphore(MAX_PERMITS, true) : null);
|
||||
}
|
||||
|
||||
public void acquire()
|
||||
{
|
||||
acquisitionSemaphore.acquireUninterruptibly();
|
||||
}
|
||||
|
||||
public void release()
|
||||
{
|
||||
acquisitionSemaphore.release();
|
||||
}
|
||||
|
||||
public void suspend()
|
||||
{
|
||||
acquisitionSemaphore.acquireUninterruptibly(MAX_PERMITS);
|
||||
}
|
||||
|
||||
public void resume()
|
||||
{
|
||||
acquisitionSemaphore.release(MAX_PERMITS);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue