Thursday, August 30, 2012

How to enable jmx-agent to monitor a java process from remote machine:

A quick tip on how to enable jmx-agent to monitor a java process from remote machine:

Add following system property in the java process while starting it: “-Dcom.sun.management.jmxremote.port=<port number>”
 
We can add security features as well to it: 
For example, (run com.example.MyApp with jmx-agent enabled) 
% java -Dcom.sun.management.jmxremote.port=3000
-Dcom.sun.management.jmxremote.password.file=password.properties
-Dcom.sun.management.jmxremote.access.file=access.properties
-Djavax.net.ssl.keyStore=keystore
-Djavax.net.ssl.keyStorePassword=password
com.example.MyApp


Monday, June 25, 2012

Security - Array is stored directly

Sonar Violation: Security - Array is stored directly
Means: Constructors and methods receiving arrays should clone objects and store the copy. This prevents future changes from the user (caller/client) affect the internal functionality.

public void setMyArray(String[] myArray) {
  this.myArray = myArray;
}

Solution:

public void setMyArray(String[] newMyArray) {
  if(newMyArray == null) {
    this.myArray = new String[0];
  } else {
   this.myArray = Arrays.copyOf(newMyArray, newMyArray.length);
  }
}

Friday, May 18, 2012

JBoss - Too many open files

Issue: I faced this issue in JBoss while doing load testing. Under heavy load, jboss http connector crashed and it refused to accept any new connections. On checking logs, I found out that the root cause was “Too many open files” issue.

 

Resolution: “Too many open files” – this issue is a linux issue. OS enforces a limit on each process for maximum number of files that can get attached to a process. Normally the default value is 1024. (Default value can be checked using this command: “ulimit -n“) This value is not sufficient for processes like application containers.

 

All the files associated with given process can be seen with this command: lsof -p <pid>

 

More details about how can this value be changed is available on this wonderful blog post - http://tech-torch.blogspot.com/2009/07/linux-ubuntu-tomcat-too-many-open-files.html

 

One thing missing in this blog is that for ‘root’ user, you have to specifically mention the user name while modifying /etc/security/limits.conf file. Wild cards are not applicable for root user.

For example, following lines should be enter in /etc/security/limits.conf file for root user –

 

root            soft      nofile        4096

root            hard    nofile        8192

 

Tek-Olweiz,

Sarang

 

Friday, May 4, 2012

JBoss TimerService - bug fix

As such the TimerService implementation is not stable in jboss6.1.
The version of timer-service library (of JBoss6.1.0.Final) itself says it is only an ALPHA lib… not a GA (jboss-ejb3-timerservice-mk2.jar, version 1.0.0-alpha-13)

I was facing an issue with the TimerService and while looking for a solution, found out JBoss team doesn’t support issues of JBoss-6x any longer.
The issue was related to Transaction management in Timer Service implementation.

Following is the JIRA defect and attached is the library with fix of the issue.
You can get the source code also at my GitHub page mentioned below.

Fixed lib jar file – https://www.box.com/s/5c6d4a99cfd7e07df091/1/275092885/2167714863/1

Regards,
Sarang

Tuesday, February 21, 2012

JBoss Trimming - remove JSF

If you are not using JSF, you can trim jboss and remove JSF from getting deployed!
You can do this by commenting everything in the deployers\jsf.deployer\META-INF\jsf-integration-deployer-jboss-beans.xml.
Just keep following lines.
<?xml version="1.0" encoding="UTF-8"?>
<!--
    JBoss JSF + JBossAS integration
-->
<deployment xmlns="urn:jboss:bean-deployer:2.0">
</deployment>

This will save a lot of time while starting jboss… the time jboss uses in JSF initialization.

Courtesy: Vishnu Gopal Singhal

Friday, February 10, 2012

Android installation issue

I was facing problem while downloading 3rd party plugins for Android SDK.
Following was the error I was facing –
“Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-1.xml
reason: Connection to https://dl-ssl.google.com refused”

Following is the solution -
Go to the SDK Manager (Navigate to it on the computer, not from eclipse), then open it up and provide proxy. Also check the checkbox which says force http connection for https urls.
(I was behind a proxy.)

Friday, December 16, 2011

Java - getClass().getClassLoader().getResource("myfolder/data/file.txt").getPath();

Java - getClass().getClassLoader().getResource("myfolder/data/file.txt").getPath();

 

A relatively simple concept that confuses many java beginners!

 

Java Code:

String path = getClass().getClassLoader().getResource("myfolder/data/file.txt").getPath();

 

Means:

This code will try to get exact path of foldermyfolder/data/file.txt”.

The parent folder of this folder “myfolder/data/file.txt” should be mentioned in class path.

 

e.g. If the exact path of this folder is “C:/properties/myfolder/data/file.txt”; path “C:/properties” should be mentioned in classpath of the application (build-path in eclipse). When the above mentioned code is executed in application, it returns the exact path of the folder location and assigns it to ‘path’ variable.

 

Hence after execution of this code, ‘path’ variable will contain value “C:/properties/myfolder/data/file.txt”.

 

If we change root location of the application or we change folder structure of the parent folder of “myfolder/data/file.txt“, we will need to change only classpath.

This avoids hard-coding of the absolute path in source code. (Important for portability of application across windows and unix platforms.)

 

 

Monday, December 5, 2011

Hibernate: wrong usage of merge()

Note the wrong usage of merge():

merge() doesn't make the object passed into it persistent, it returns another instance with the same state instead,

So you should write: bean.setManufacturer(s.merge(bean.getManufacturer()));

 

 

Tuesday, November 15, 2011

type-mappinmg for byte[] in standardjbosscmp-jdbc.xml

http://community.jboss.org/thread/23104?decorator=print&displayFullThread=true

 

After many hours investigating this problem I have found a solution myself.

Here the mapping required in standardjbosscmp-jdbc.xml if you want to read and write to blob fields using an byte[] java type rather than some serialized java.lang.Object:

<java-type>[B</java-type>
<jdbc-type>VARBINARY</jdbc-type>
<sql-type>IMAGE</sql-type>

and the entity bean abstract get & set methods will be as below:

public abstract byte[] getField();
public abstract void setField(byte[] value);

Now I can read and write to the blob using array's of bytes just like any byte[] which is simple, neat and tidy coding exercise.

I guess you would need to be a bit careful with really big blobs as when the entity bean is read from the DB it will bring the whole blob into memory and hold it in a byte[].

The <java-type> of '[B' means a byte[] type. This you will not find in any documentation. I found this by looking at the JBoss source code in the process of trying to understand what was going on with blobs. The class in where I found the '[B' is:

org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil

 

Cheers,

Sarang

As I mentioned in my previous post on productivity, using the productivity tools DOES help a lot.... a snapshot of my productivity analysis since I started using these tools. I have been, according to RescueTime, amongst top 13% productive people! :)
Not reading too much into these statistics, I can definitely say that I have felt considerable improvement in my productivity!






Enhanced by Zemanta

Wednesday, November 2, 2011

Some good productivity tools

Some excellent FOSS tools to enhance productivity –
  1. Grindstone – Timers for Task Management
  2. RescueTime – For analyzing computer usage
  3. ManicTime tracker – Similar to RescueTime
  4. Approach: Pomodoro Technique
Will blog about more details sometime later.
Right now, I don’t want this post to affect my productivity ;)

And yeah, this DOES help a lot!!!

Cheers,
Sarang

Tuesday, October 18, 2011

VNC Configuration

Some of the configuration tips for VNC server instances and window sizes.

To create new instance, add an entry in file /etc/sysconfig/vncservers.
For example, I have created two instances and following is the content of this file:

VNCSERVERS="1:root 2:root"
VNCSERVERARGS[1]="-geometry 1280x800 -depth 16"
VNCSERVERARGS[2]="-geometry 1260x710 -depth 16"

The first line indicates the usernames to access each of the server instances.
In this case both are ‘root’. So it can be accesses by entering <ip-address>:1 and <ip-address>:2 in the VNC client window.

The reason for creating two instances here is nothing but two different resolutions.
The first instance’s resolution “1280x800” is best for full-screen usage.
The second instance’s resolution “1260x710” is best for full-size client window. (Expand the vnc client window to fill size by clicking on ‘Maximize’ button on top right corner)

One more important point, you need to keep ‘vncconfig’ running to be able to share clipboard to/from your desktop to VNC server.
Use following command to start vncconfig:
vncconfig -nowin &

Cheers,
Sarang

Enhanced by Zemanta

Wednesday, October 5, 2011

Eclipse Proxy settings - bug and workaround

Many a times I experienced weird behavior of eclipse network connectivity (despite providing proxy settings) especially while installing plugins from update sites.
However, didn’t pay enough heed to the issues and many a times moved on with installing the plugins by manually downloading it.

With Eclipse Indigo, as the Eclipse marketplace makes plugin installation quite easier, I thought of checking out the exact issue with eclipse network connectivity.

As always, found the bug and work around easily by searching on net (community power!!!)

The bug is with Eclipse proxy settings. Normally, when we enable proxy on eclipse, we enable all types of proxies – HTTP, HTTPS and SOCKS.
The issue is that if you add ‘SOCKS’ proxy entry, eclipse will ignore HTTP/HTTPS whereas normally you will always connect to an HTTP/S url.
So the solution is that remove ‘SOCKS’ proxy entry and keep only HTTP/HTTPS entry. (Make sure you select Active provider as ‘Manual’)

Following is the screenshot for the proxy setting.


Update: You need to restart your eclipse after making this change.

Cheers,
Sarang
Enhanced by Zemanta

Subclipse plugin installation in Eclipse Indigo on RHEL- Bug and resolution

I was facing issue while using subclipse plugin in my Eclipse Indigo on my RHEL (Redhat Linux) box.
Installation was successful but was giving error while connecting with SVN.

On searching for the solution, I found out that the issue was related to JavaHL. JavaHL is a "High Level" API and is provided with custom written C++ code to serve as the JNI bridge between Java code and the native libraries (C-libraries).

So the solution to the issue is providing JavaHL in eclipse classpath.
For me, the solution was relatively simple as I already had CollabNet SVN client installed on my box. If you don’t have thisclient installed, you will have to install it first from here – http://www.collab.net/downloads/subversion/redhat.html

CollabNet client contains required library (library name is libsvnjavahl-1.so)
So add following vm argument in your eclipse.ini right after the line that reads “-vmargs” and that should resolve the issue.
 
-Djava.library.path=/opt/CollabNet_Subversion/lib
 
Your eclipse.ini might look like this –
 
-showsplash
org.eclipse.platform
-framework
plugins/org.eclipse.osgi_3.4.0.v20080605-1900.jar
-vmargs
-Djava.library.path=/opt/CollabNet_Subversion/lib
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
-XX:MaxPermSize=256m

Refer this wiki page for more details and for resolving this issue on other operating systems - http://subclipse.tigris.org/wiki/JavaHL

Cheers,
Sarang
Enhanced by Zemanta

Friday, September 30, 2011

Code to compare difference in working copy and specific branch of svn for multiple directories:

Code to compare difference in working copy and specific branch of svn for multiple directories:

find . -type d -maxdepth 1 -printf "%f\n" | while read -d $'\n' file
do
  echo "svn diff --old http://135.10.61.14/svn/DAWN/tags/Dev_Version0.11.5/$file  --new ./$file  > ../diff/$file.diff"
  svn diff --old http://135.10.61.14/svn/DAWN/tags/Dev_Version0.11.5/$file  --new ./$file  > ../diff/$file.diff
  #echo "$file"
done
Enhanced by Zemanta

Eclipse settings for performance improvement

If you use eclipse, I am sure you have come across moments when you banged your head waiting for eclipse to respond.
By applying following settings, your eclipse performance should become bad, which otherwise is worst! (There is no such thing in this world called "Good Eclipse performance".)

Update your eclipse.ini file (in your <ECLIPSE-HOME> directory) with following settings.
(VERYIMPORTANT: Do NOT miss to update the “-vm” parameter (in bold below) to your own <JAVA_HOME>)

-startup
plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-product
org.eclipse.epp.package.jee.product
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
-showlocation
-vm
C:\PROGRA~1\Java\jdk1.6.0_20\jre\bin\client\jvm.dll
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512M
-Xmx512M
-Xss128k
-XX:NewSize=128M
-XX:MaxNewSize=128M
-XX:PermSize=128m
-XX:MaxPermSize=128m
-XX:MaxGCPauseMillis=10
-XX:MaxHeapFreeRatio=70
-XX:+UseConcMarkSweepGC
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:CompileThreshold=5
-Dcom.sun.management.jmxremote

After applying these settings, if you ever get StackOverflowError, increase the value of “-Xss” to 192m (or 256m, if required).
To understand the significance of “-Xss” parameter, read this post on my blog.
Enhanced by Zemanta

Monday, August 22, 2011

Update for Java1.6: Thread Count supported by JVM on various OSs

Updating the table from previous post (Thread Count supported by JVM on various OSs) for Java 1.6

OS(32-bit)
Java-Version
Heap-Size
ThreadStackSize
Thread-count
RHEL
1.5
1024m
Default
3636
RHEL
1.5
1250m
Default
3196
RHEL
1.5
1536m
Default
2632
RHEL
1.5
1750m
Default
2206
RHEL
1.5
2g
Default
1615
RHEL
1.5
1024m
128k
13947
RHEL
1.5
1250m
128k
12245
RHEL
1.5
1536m
128k
10083
RHEL
1.5
1750m
128k
8466
RHEL
1.5
2g
128k
6215
RHEL
1.5
1024m
256k
7183
RHEL
1.5
1250m
256k
6301
RHEL
1.5
1536m
256k
5190
RHEL
1.5
1750m
256k
4365
RHEL
1.5
2g
256k
3198
WinXP
1.5
1024m
Default
3388
WinXP
1.5
1250m
Default
2495
WinXP
1.5
1536m
Default
NA
WinXP
1.5
1750m
Default
NA
WinXP
1.5
2g
Default
NA
WinXP
1.5
1024m
128k
3388
WinXP
1.5
1250m
128k
2495
WinXP
1.5
1536m
128k
NA
WinXP
1.5
1750m
128k
NA
WinXP
1.5
2g
128k
NA
WinXP
1.5
1024m
256k
855
WinXP
1.5
1250m
256k
631
WinXP
1.5
1536m
256k
NA
WinXP
1.5
1750m
256k
NA
WinXP
1.5
2g
256k
NA
RHEL
1.6
1024m
Default
5851
RHEL
1.6
1250m
Default
5156
RHEL
1.6
1536m
Default
4272
RHEL
1.6
1750m
Default
3603
RHEL
1.6
2g
Default
2689
RHEL
1.6
1024m
128k
14005
RHEL
1.6
1250m
128k
12323
RHEL
1.6
1536m
128k
10213
RHEL
1.6
1750m
128k
8640
RHEL
1.6
2g
128k
6422
RHEL
1.6
1024m
256k
7278
RHEL
1.6
1250m
256k
6406
RHEL
1.6
1536m
256k
5308
RHEL
1.6
1750m
256k
4486
RHEL
1.6
2g
256k
3340
WinXP
1.6
1024m
Default
2657
WinXP
1.6
1250m
Default
1991
WinXP
1.6
1536m
Default
NA
WinXP
1.6
1750m
Default
NA
WinXP
1.6
2g
Default
NA
WinXP
1.6
1024m
128k
6285
WinXP
1.6
1250m
128k
4774
WinXP
1.6
1536m
128k
NA
WinXP
1.6
1750m
128k
NA
WinXP
1.6
2g
128k
NA
WinXP
1.6
1024m
256k
3312
WinXP
1.6
1250m
256k
2478
WinXP
1.6
1536m
256k
NA
WinXP
1.6
1750m
256k
NA
WinXP
1.6
2g
256k
NA

Cheers,
Sarang