Category Archives: Java

Double-checked locking

https://www.securecoding.cert.org/confluence/display/java/LCK10-J.+Use+a+correct+form+of+the+double-checked+locking+idiom The double-checked locking idiom is a software design pattern used to reduce the overhead of acquiring a lock by first testing the locking criterion without actually acquiring the lock. Double-checked locking improves performance by limiting synchronization to the rare case of computing the field’s value or constructing a new instance for the field to […]

Read more

JDBI

http://www.jdbi.org/ DataSource ds = JdbcConnectionPool.create(“jdbc:h2:mem:test”, “username”, “password”); DBI dbi = new DBI(ds); Handle h = dbi.open(); h.execute(“create table something (id int primary key, name varchar(100))”); h.execute(“insert into something (id, name) values (?, ?)”, 1, “Brian”); String name = h.createQuery(“select name from something where id = :id”) .bind(“id”, 1) .map(StringMapper.FIRST) .first(); assertThat(name, equalTo(“Brian”)); h.close();

Read more

Netty tutorials

http://seeallhearall.blogspot.ru/2012/05/netty-tutorial-part-1-introduction-to.htmlhttp://seeallhearall.blogspot.ru/2012/06/netty-tutorial-part-15-on-channel.html

Read more

Validation JSR-303 benchmarking

http://carinae.net/2010/06/benchmarking-hibernate-validator-and-apache-beanvalidation-the-two-jsr-303-implementations/ Apache BeanValidation Formerly Agimatec Validation, since March 2010 it has migrated to Apache where it is currently under incubation. One of its most useful extra features is the ability to perform method validation using the same kind of JSR-303 annotations. The benchmarked version is: 0.1-incubating. Hibernate Validator The reference implementation of the standard, coming […]

Read more

Purging connections from JDBC connection pool

http://docs.oracle.com/cd/E24329_01/web.1211/e24376/phys_conr.htm#JDBCP1037 http://docs.tpu.ru/docs/oracle/en/fmw/11.1.1.6.0/apirefs.1111/e13941/toc.htm   There are special tasks when we need to explicitly close physical connection to the database: clean errors on the connection for example. General standard solution does not exist but for WebLogic data source we can do the following: 1. Ensure that “Remove Infected Connections Enabled” option is set to true; true is […]

Read more

Configuring SSL for WebLogic managed server

General considerations: https://timtaubert.de/blog/2014/10/deploying-tls-the-hard-way/ To check current SSL/TLS version and cipher suite used for SSL connections: $ openssl s_client -connect hostname:8888 example output: New, TLSv1/SSLv3, Cipher is AES128-SHA Server public key is 2048 bit Secure Renegotiation IS supported Compression: NONE Expansion: NONE SSL-Session: Protocol  : TLSv1 Cipher    : AES128-SHA Session-ID: 5523B18F98C687FD8E76527F827E86EA47C603C8D105DF1D5428468A83ACA7D5 Session-ID-ctx: Master-Key: 7C2824A28A3722A8072082D6CB69ED3C2D6DA669B7D46E4FC994AFB71150B324A0D55E59569377FF9C93A8DF0DE80BE1 Key-Arg   : […]

Read more

Configuring Java-based Node Manager

Create script for managing Node Manager script: /etc/init.d/nodemgr. Register it as a service start/stop script: #  chkconfig –add nodemgr Now we may start and stop the service as: # service nodemgr start # service nodemgr stop   ———————————————————————————————————————————- #!/bin/sh # # nodemgr Oracle Weblogic NodeManager service # ### BEGIN INIT INFO # Provides: nodemgr # […]

Read more

Configuring Script-based Node Manager

Further it is supposed that WebLogic server is already installed on the machine and domains are configured. Let us take “base_domain” as the domain name in the following example commands. 1. Create OS user > useradd -g bea -m ndmgr > passwd ndmgr add WL_HOME/common/bin to the PATH variable. It is recommended that node manager […]

Read more

JSF: button and commandButton difference

http://stackoverflow.com/questions/13070537/difference-between-hbutton-and-hcommandbutton The <h:button> generates a HTML <input type=”button”> which uses JavaScript to navigate to URL as represented by the given navigation case outcome by a HTTP GET request. E.g. <h:button value=”GET button” outcome=”otherpage” /> will generate <input type=”button” onclick=”window.location.href=’/contextpath/otherpage.xhtml’; return false;” value=”GET button” /> Even though this ends up in a (bookmarkable) URL change in […]

Read more

Configuring datasource on Tomcat

Add Resource tag into Context, for example^ <Resource name=”jdbc/PostgreDS” auth=”Container” type=”javax.sql.DataSource” driverClassName=”org.postgresql.Driver” url=”jdbc:postgresql://127.0.0.1:5432/schema” username=”schema” password=”1234″ maxActive=”50″ maxIdle=”10″ maxWait=”-1″/> <Resource name=”jdbc/MysqlDS” auth=”Container” type=”javax.sql.DataSource” driverClassName=”com.mysql.jdbc.Driver” url=”jdbc:mysql://localhost:3306/schema” username=”user” password=”1234″ maxActive=”50″ maxIdle=”10″ maxWait=”-1″/>  

Read more

IO Streams

http://tutorials.jenkov.com/java-io/overview.html   Byte Based Character Based Input Output Input Output Basic InputStream OutputStream Reader InputStreamReader Writer OutputStreamWriter Arrays ByteArrayInputStream ByteArrayOutputStream CharArrayReader CharArrayWriter Files FileInputStream RandomAccessFile FileOutputStream RandomAccessFile FileReader FileWriter Pipes PipedInputStream PipedOutputStream PipedReader PipedWriter Buffering BufferedInputStream BufferedOutputStream BufferedReader BufferedWriter Filtering FilterInputStream FilterOutputStream FilterReader FilterWriter Parsing PushbackInputStream StreamTokenizer PushbackReader LineNumberReader Strings StringReader StringWriter Data DataInputStream DataOutputStream […]

Read more

How to run jsf 2.0 on Weblogic 10

1. Minimal Weblogic version number should be 10.3.6. This release contains jsf 2.0 implementation as a jar file that should be installed separately. We deploy $WEBLOGIC_HOME/modules/javax.jsf_1.1.0.0_1-2.jar as a library onto Weblogic server. 2. Our application should contain: in web.xml: <context-param> <param-name>com.sun.faces.expressionFactory</param-name> <param-value>com.sun.el.ExpressionFactoryImpl</param-value> </context-param> in weblogic.xml: <library-ref> <library-name>jsf</library-name> <specification-version>2.0</specification-version> <implementation-version>1.0.0.0_2-0-2</implementation-version> <exact-match>true</exact-match> </library-ref> <container-descriptor> <prefer-application-packages> <package-name>com.sun.el.*</package-name> <package-name>javax.el.*</package-name> […]

Read more

GlassFish: how to reset admin password

How to Recover Glassfish admin password Replace the file “admin-keyfile” under “/installation-folder/glassfish/domains/domain1/config/” with same of any of working domains file. So that password will be same used in domains used earlier and you may change the password once after the login. For glassfish 4, the content of admin-keyfile for password “changit” is: admin;{SSHA256}dvCEGFNHGtSyXIhJvwR5FnviH+u8fCadrUIqp6uJc1tP9Bv10CGT7A==;asadmin The content […]

Read more