Troubleshout Open file limit

Show no of open files sorted by PID - lsof | awk '{ print $2; }' | uniq -c | sort -rn | head Check individual file limits of a process - cat /proc/<PID>/limits to obtain a precise count of the open files at given instant of time - ls /proc/<PID>/fd | wc -l This will list all open files with given process - lsof -p <PID> In some cases you might have to look at the open file limit of the process which started your process. [Read More]

Setup virtualbox on Ubuntu Server 64 Bit

Setup virtual box on ubuntu server 64bit and use phpvirtualbox to access webui of VirtualBox to manage the instances on virtualbox. Ubuntu Server 64bit VirtualBox4.3. phpvirtualbox Running VirtualBox and phpvirtualbox on the same machine. I mostly followed this blog http://santi-bassett.blogspot.in/2013/01/installing-virtualbox-on-ubuntu-server.html. Except few changes. When I installed virtual box I installed latest version 4.3.* location of phpvirtualbox has been changed to sourceforge.net http://sourceforge.net/projects/phpvirtualbox/files/ and used phpvirtualbox 4.3.1 version. However even after following all the steps right I got following error [Read More]

GWT browser specific css

Yea it is possible to write browser specific css with GWT application which uses CSS through CssResource. @if user.agent gecko1_8 { .startup p { color: #000000; text-shadow: 0 0 3px #000000; } } @else { .startup p { color: #000000; } } Note: You can use this logical if else and many more other expression inside css which are used inside GWT code. Only through CssResource interface. If you are directly using the respective css inside html main source file then this will not work. [Read More]
GWT 

GWT Jquery integration

It is very easy to have GWT Jquery integration using gwtquery. Follow below steps Add maven dependency for gwtquery, at the time of writing this article it was 1.4.2 and tested it with GWT 2.5.0 version. <dependency> <groupId>com.googlecode.gwtquery</groupId> <artifactId>gwtquery</artifactId> <version>1.4.2</version> <scope>provided</scope> </dependency> Then inherit your module from required gwtquery module. <inherits name='com.google.gwt.query.Query'/> User jquery api wrappers as follows. import static com.google.gwt.query.client.GQuery.$; .. ... public class GwtJquery implements EntryPoint { @Override public void onModuleLoad() { $("#startup"). [Read More]

Eclipse getting crashed randomly on ubuntu

If your eclipse is getting crashed randomly and that too frequently look at the crash reported. This crash report will be placed in the directory from where you start the eclipse and search for /usr/lib/x86\_64-linux-gnu/gtk-2.0/modules/liboverlay-scrollbar.so. If find this string then this issues of overlay scrollbar library. This will be solved once you remove that library. Sometimes, you will not find crash report generated, even in that case it is most probably the issue of overlay scrollbar. [Read More]

Redirect process output to std output when you fork one process from another process.

In the situation where you want to redirect input / output of one process to the std input output of parent process (from which you are starting first process). You can make use of inheritIO() method of a ProcessBuilder. ProcessBuilder pb = new ProcessBuilder("command", "argument); pb.directory(new File(<directory from where you want to run the command>)); pb.inheritIO(); Process p = pb.start(); p.waitFor(); It may not be necessary to call waitFor() method in above code. [Read More]

Quartz Scheduler with Google Guice

To integrate Quartz with Guice. One can follow below steps. The most important part is, we should be able to inject dependencies inside Job. To provide injectable Scheduler Instance we need to write Scheduler provider as follows: import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.impl.StdSchedulerFactory; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; /** * @author Pandurang Patil 27-Apr-2014 * */ @Singleton public class SchedulerProvider implements Provider<Scheduler> { private Scheduler scheduler; @Inject public SchedulerProvider(SchedulerJobFactory jobFactory) throws SchedulerException { scheduler = new StdSchedulerFactory(). [Read More]

Java: Retreive ByteArray from Direct ByteBuffer and convert it to String

I assume you understand what is Direct ByteBuffer. I was trying to retrieve byte[] from Direct ByteBuffer

ByteBuffer buffer = ByteBuffer.allocateDirect(10000);
.....
.....
buffer.flip();
byte[] data = buffer.array();

and I was getting this error

Exception in thread "main" java.lang.UnsupportedOperationException
 at java.nio.ByteBuffer.array(ByteBuffer.java:959)

I was able to solve this as follows

ByteBuffer buffer = ByteBuffer.allocateDirect(10000);
.....
.....
buffer.flip();
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
// Here you hava data populated inside data[] array
String token = new String(data);

ZeroMQ ipc not working

If you are using Zero MQ IPC endpoint url like ipc://someendpoint. Then communication between two threads of same process will work perfectly fine. But it will fail if you are trying to communicate across the processes. If you look at ZeroMQ document properly end point should correspond to path. Thats where above end point url works fine for intra process communication as this file someendpoint will correspond to file in current directory from where you are running this app. [Read More]

Java: Add shutdown hook invoked even with CTRL + C

Add Shutdown hook with JVM, which will be invoked even when application is killed by pressing CTRL + C Create a separate class which extends java.lang.Thread class or implements java.lang.Runnable interface public class AppShutDownHook extends Thread { @Override public void run() { // TODO: Complete your shutdown activity here. } } Register this thread with Java Runtime in your code where your application is getting initialised. Most probably inside main. [Read More]