Sunday 19 May 2013

don't know how to handle message of type ' b'. are you missing a protocol encoder



Please write IoBuffer in the Protocol Decoder
in Apache Mina Framework.

If you try to send String/ or any other object it will throw some thing like,
don't know how to handle message of type ' b'. are you missing a protocol encoder

ProtocolEncoderOutput

java.lang.IllegalArgumentException: buf is empty. Forgot to call flip()?


It has two chances possible for this error:
1. Forget to call flip() after put/write into Buffer.
2. If you used wrap() , then no need to call flip().Because wrap() will set position to Zero. it is ready for read from Buffer.



Here are the better articles I suggest:

ByteBuffer
ByteBuffer Tutorial

Please post me here I will help you on this.

Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory


This will come while executing the cmd/shell from java

might be the problem will be more like
command you are trying to execute will be a problem.

So please put more concentration on arguments you ar passing to application.

I also suggest this Article on this


I also faced same issues like above,
My mistake is
java -jar "Jaraname.jar" classname arg1 arg2

Totally here 3 args, even arg classname is not required for me...which is also trying to pass as an argument and creates the problem.

Jar is Runnable jar file with Manifest generated by eclipse in my case.

Windows / Linux both are same no need to take extra caring for os dependent.

One of the Best Article was from Javaworld.

Please post me for any solutions like this. I will help you with little Charge
:-)



how to make executor as daemon thread




You need to use a new ThreadFactory that creates daemon threads. See this answer here


import these classes:


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;



Add this Class


static class DaemonThreadFactory implements ThreadFactory {
   public Thread newThread(Runnable r) {
       Thread thread = new Thread(r);
       thread.setDaemon(true);
       return thread;
   }
}


Use like this:

private static DaemonThreadFactory dtf = new DaemonThreadFactory();
private static ExecutorService service= Executors.newFixedThreadPool(5, dtf);


If you need any example on this please leave a comment i will reply.



--------------------------------


you can also use Anonumous class like this:

ExecutorService pool = Executors.newSingleThreadExecutor(new ThreadFactory() {
   @Override
   public Thread newThread(Runnable runnable) {
      Thread thread = Executors.defaultThreadFactory().newThread(runnable);
      thread.setDaemon(true);
      return thread;
   }
});



Tuesday 14 May 2013

First Shell Script to Run Java Applications in Solaris


#!/bin/bash
JAVA_HOME=/usr/jdk/jdk1.7.0_07/bin
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME


java -classpath .:./config:./lib/1.jar:./lib/2.jar:com.test.run.ClassName

Query that returns list of all Stored Procedures in an MS SQL database


select * from information_schema.routines
where routine_type = 'PROCEDURE'

Friday 10 May 2013

Thursday 9 May 2013

Solaris 11, How to check Java version in Solaris

First time I am using Solaris and i don't even know anything in solaris 11.
Solaris 11 commands
admin@solaris:/$ java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) Client VM (build 23.3-b01, mixed mode)

By default Solaris have jdk latest version.