Object Pooling, a common question, but with not easy to find solutions :
https://stackoverflow.com/questions/43735067/manage-client-socket-pool
https://stackoverflow.com/questions/939734/tips-for-using-commons-pool-in-production
https://github.com/roma/roma-java-client/blob/master/java/client/src/main/java/jp/co/rakuten/rit/roma/client/SocketPool.java
https://commons.apache.org/proper/commons-pool/
http://www.vibur.org/vibur-object-pool/
http://danielw.cn/fast-object-pool/
27 November 2018
CEStreamExhausted anti-pattern
This exception is thrown when EOF is found. Literally is an anti-pattern (like a goto)
https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/sun/misc/CEStreamExhausted.java
/** This exception is thrown when EOF is reached */
public class CEStreamExhausted extends IOException { };
Which is executed at line 117 de BASE64Decoder :
https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/sun/misc/BASE64Decoder.java
do {
i = inStream.read();
if (i == -1) {
throw new CEStreamExhausted();
}
} while (i == '\n' || i == '\r');
Therefore it's a false-positive if any APM raise it.
--------------------------------------------------------------------------------
https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/sun/misc/CEStreamExhausted.java
/** This exception is thrown when EOF is reached */
public class CEStreamExhausted extends IOException { };
Which is executed at line 117 de BASE64Decoder :
https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/sun/misc/BASE64Decoder.java
do {
i = inStream.read();
if (i == -1) {
throw new CEStreamExhausted();
}
} while (i == '\n' || i == '\r');
Therefore it's a false-positive if any APM raise it.
--------------------------------------------------------------------------------
Me faltó agregar que la clase que llama a la lanza la excepcion en cuestion es: CharacterDecoder.java
Y lo que hace es tener un loop infinito while(true) que se sale de ahi al atrapar dicha exception.
Por lo tanto queda demostrado que es un falso-positivo.
| while (true) { | |
| int length; | |
| try { | |
| length = decodeLinePrefix(ps, bStream); | |
| for (i = 0; (i+bytesPerAtom()) < length; i += bytesPerAtom()) { | |
| decodeAtom(ps, bStream, bytesPerAtom()); | |
| totalBytes += bytesPerAtom(); | |
| } | |
| if ((i + bytesPerAtom()) == length) { | |
| decodeAtom(ps, bStream, bytesPerAtom()); | |
| totalBytes += bytesPerAtom(); | |
| } else { | |
| decodeAtom(ps, bStream, length - i); | |
| totalBytes += (length - i); | |
| } | |
| decodeLineSuffix(ps, bStream); | |
| } catch (CEStreamExhausted e) { | |
| break; | |
| } | |
26 November 2018
Log4j config ?
A way to check if log4j is configurated at runtime.
log4j IsConfigured :::
/**
* Returns true if it appears that log4j have been previously configured. This
* code checks to see if there are any appenders defined for log4j which is the
* definitive way to tell if log4j is already initialized
*/
private static boolean isConfigured() {
Enumeration appenders = Logger.getRoot().getAllAppenders();
if (appenders.hasMoreElements()) {
return true;
} else {
Enumeration loggers = LogManager.getCurrentLoggers();
while (loggers.hasMoreElements()) {
Logger c = (Logger) loggers.nextElement();
if (c.getAllAppenders().hasMoreElements())
return true;
}
}
return false;
}
http://wiki.apache.org/logging-log4j/UsefulCode
http://logging.apache.org/log4j/1.2/xref-test/org/apache/log4j/defaultInit/TestCase4.html
https://web.archive.org/web/20130401061324/http://dsiutils.dsi.unimi.it/
https://web.archive.org/web/20081211154329/http://dsiutils.dsi.unimi.it/docs/it/unimi/dsi/Util.html
https://web.archive.org/web/20110303190435/http://www.screaming-penguin.com/node/7622
log4j IsConfigured :::
/**
* Returns true if it appears that log4j have been previously configured. This
* code checks to see if there are any appenders defined for log4j which is the
* definitive way to tell if log4j is already initialized
*/
private static boolean isConfigured() {
Enumeration appenders = Logger.getRoot().getAllAppenders();
if (appenders.hasMoreElements()) {
return true;
} else {
Enumeration loggers = LogManager.getCurrentLoggers();
while (loggers.hasMoreElements()) {
Logger c = (Logger) loggers.nextElement();
if (c.getAllAppenders().hasMoreElements())
return true;
}
}
return false;
}
http://wiki.apache.org/logging-log4j/UsefulCode
http://logging.apache.org/log4j/1.2/xref-test/org/apache/log4j/defaultInit/TestCase4.html
https://web.archive.org/web/20130401061324/http://dsiutils.dsi.unimi.it/
https://web.archive.org/web/20081211154329/http://dsiutils.dsi.unimi.it/docs/it/unimi/dsi/Util.html
https://web.archive.org/web/20110303190435/http://www.screaming-penguin.com/node/7622