Categories

Amazon fire

Latest books

Installing and configuring Java on Windows/Linux

Your Ad Here

Java is an object-oriented programming language developed by Sun Microsystems in the early 1990s. Java applications are compiled to bytecode, which at runtime is either interpreted or compiled to native machine code for execution.

The language itself derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. JavaScript, a scripting language, shares a similar name and has similar syntax, but is not directly related to Java.

To compile and run a java program we need to install java platform. JDK (Java Development Kit). JDK is the basic set of tools required to compile and run java programs. This section enables you to download JDK and teaches you the steps to install it.

Install Java For Windowns

Download and Install JDK

download the latest version of JDK click bellow link

 http://java.sun.com/javase/downloads/index.jsp.

Download exe file and install jdk.

For installing jdk, double click on that latest file.

You can see message like this

 

Your installation will be in progress like this

 

Click on the Accept License Agreement

 

Choose Custom setup

 

If you want to give some path of directory you can choose for java otherwise click ok for current file location where your jdk will be install as per set up.

 

 

After clicking ok button your screen will be like this

 

 

 

Click next in the following window

 

Generally no need to change destination folder so click ok for JRE installation

 

Installation in progress

 

Successfully install so click on finish button

 

Check your installation in following folder

1.jdk1.6.0_01

 2.jre1.6.0_01″

Folder path: C:\ Program Files\ java (if you not change path )

 

Environment variable setup for running your java compile and run programs.

My computer à system property à click on  Advance Tab à Click on Environment Variable

  1. 1.     Select Path (in system variable)= Click on edit button and add the following path

c:\Program Files\Java\jdk1.6.0_01\bin;

 

System Variable

Check if JAVA_HOME exists or not if there is no JAVA_HOME in system variable then

  1. 1.     Click on new button give Variable NAME = JAVA_HOME
  2. 2.     Value = C:\Program Files\Java\jdk1.6.0_01                                                                                   ( if the path is different give your jdk folder path)

 

 

 

Check your installation in correct or not

  1. 1.     Command prompt (dos command prompt)
  2. 2.     type command javac  for compile your jvm and give you all details of your java

 

Your Ad Here

How to setup Zookeeper in cluster environment.

Your Ad Here

Clustered (Multi-Server) Setup

For reliable ZooKeeper service, you should deploy ZooKeeper in a cluster known as an ensemble. As long as a majority of the ensemble are up, the service will be available. Because Zookeeper requires a majority, it is best to use an odd number of machines. For ZooKeeper Administrator’s Guide

Example, with four machines ZooKeeper can only handle the failure of a single machine; if two machines fail, the remaining two machines do not constitute a majority. However, with five machines ZooKeeper can handle the failure of two machines. Here are the steps to setting a server that will be part of an ensemble. These steps should be performed on every host in the ensemble:

1. Install the Java JDK. You can use the native packaging system for your system, or download the JDK from:

  • http://java.sun.com/javase/downloads/index.jsp

2. Set the Java heap size. This is very important to avoid swapping, which will seriously degrade ZooKeeper performance. To determine the correct value, use load tests, and make sure you are well below the usage limit that would cause you to swap. Be conservative – use a maximum heap size of 3GB for a 4GB machine.

3. Install the ZooKeeper Server Package. It can be downloaded from:

  • http://hadoop.apache.org/zookeeper/releases.html

4. Create a configuration file. This file can be called anything. Use the following settings as a starting point:

  • tickTime=2000 dataDir=/var/zookeeper/ clientPort=2181
  • initLimit=5 syncLimit=2
  • server.1=zoo1:2888:3888
  • server.2=zoo2:2888:3888
  • server.3=zoo3:2888:3888

You can find the meanings of these and other configuration settings in the section Configuration Parameters. A word though about a few here: Every machine that is part of the ZooKeeper ensemble should know about every other machine in the ensemble. You accomplish this with the series of lines of the form server.id=host:port:port. The parameters host and port are straightforward. You attribute the server id to each machine by creating a file named myid, one for each server, which resides in that server’s data directory, as specified by the configuration file parameter dataDir. The myid file consists of a single line containing only the text of that machine’s id. So myid of server 1 would contain the text “1″ and nothing else. The id must be unique within the ensemble and should have a value between 1 and 255.

5. If your configuration file is set up, you can start a ZooKeeper server:

  • $ java -cp zookeeper.jar:lib/log4j-1.2.15.jar:conf org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg

QuorumPeerMain starts a ZooKeeper server, JMX management beans are also registered which allows management through a JMX management console. The ZooKeeper JMX ZooKeeper Administrator’s Guide

Document contains details on managing ZooKeeper with JMX. See the script bin/zkServer.sh, which is included in the release, for an example of starting server instances.

6. Test your deployment by connecting to the hosts: • In Java, you can run the following command to execute simple operations:

  • $ java -cp zookeeper.jar:src/java/lib/log4j-1.2.15.jar:conf:src/java/lib/jline-0.9.94.jar org.apache.zookeeper.ZooKeeperMain -server 127.0.0.1:2181
  • In C, you can compile either the single threaded client or the multithreaded client: or n the c subdirectory in the ZooKeeper sources. This compiles the single threaded client:
  • $ make cli_st And this compiles the mulithreaded client:

$ make cli_mt Running either program gives you a shell in which to execute simple file-system-like operations. To connect to ZooKeeper with the multithreaded client, for example, you would run:

$ cli_mt 127.0.0.1:2181 Source: apache.org

Your Ad Here

Apache solr replication command line handler

Your Ad Here

HTTP API Commands for the ReplicationHandler

You can use the HTTP commands below to control the ReplicationHandler’s operations.
Command Description
http://_master_host_:_port_/solr/replication?command=enablereplication Enables replication on the master for all its slaves.
http://_master_host_:_port_/solr/replication?command=disablereplication Disables replication on the master for all its slaves.
http://_host_:_port_/solr/replication?command=indexversion Returns the version of the latest replicatable index on the specified master or slave
http://_slave_host_:_port_/solr/replication?command=fetchindex Forces the specified slave to fetch a copy of the index from its master. If you like, you can pass an extra attribute such as masterUrl or compression (or any other parameter which is specified in the <lst name="slave"> tag) to do a one time replication from a master. This obviates the need for hard-coding the master in the slave.
http://_slave_host_:_port_/solr/replication?command=abortfetch Aborts copying an index from a master to the specified slave.
http://_slave_host_:_port_/solr/replication?command=enablepoll Enables the specified slave to poll for changes on the master.
http://_slave_host_:_port_/solr/replication?command=disablepoll Disables the specified slave from polling for changes on the master.
http://_slave_host_:_port_/solr/replication?command=details Retrieves configuration details and current status.
http://host:port/solr/replication?command=filelist&indexversion=<index-version-number> Retrieves a list of Lucene files present in the specified host’s index. You can discover the version number of the index by running the indexversion command.
http://_master_host_:_port_/solr/replication?command=backup Creates a backup on master if there are committed index data in the server; otherwise, does nothing. This command is useful for making periodic backups.
Your Ad Here

Java command line debugging on Linux

Your Ad Here

Thread Dumps from a JVM

A thread dump is a list of all the Java threads that are currently active in a Java Virtual Machine (JVM).

 It is highly recommended to take more than 1 thread dump. A good practice is to take 10 thread dumps at a regular interval (eg. 1 thread dump every 10 seconds).

jstack script

Here’s a script, taken from  that will take a series of thread dumps using jstack.

#!/bin/bash
if [ $# -eq 0 ]; then
    echo >&2 “Usage: jstackSeries <pid> <run_user> [ <count> [ <delay> ] ]”
    echo >&2 “    Defaults: count = 10, delay = 0.5 (seconds)”
    exit 1
fi
pid=$1          # required
user=$2         # required
count=${3:-10}  # defaults to 10 times
delay=${4:-0.5} # defaults to 0.5 seconds
while [ $count -gt 0 ]
do
    sudo -u $user jstack -l $pid >jstack.$pid.$(date +%H%M%S.%N)
    sleep $delay
    let count–
    echo -n “.”
done 

How to run:
sh jstackSeries.sh [pid] [cq5serveruser] [count] [delay]

For example:
sh jstackSeries.sh 5771 cq5serveruser 10 3

Alternative Ways to Obtain a Thread Dump

If the jstack tool is not available to you then you can take thread dumps as follows:

Note: Some tools cannot take thread dumps from the JVM if the commandline parameter -Xrs is enabled. If you are having trouble taking thread dumps then please see if this option is enabled.

Linux, Unix and Mac OSX (JDK 1.4 or lesser version)

Steps to debug Java apps :

  1. Run your program with additional switches
    java -Xdebug -Xrunjdwp:transport=dt_socket,dt_shmem,server=y,address=MyAppName,suspend=n,address=1044 -cp . test
  2. Run the command line debugger
    /usr/java/jdk_1.6.0.21/bin/jdb - connect com.sun.jdi.SharedMemoryAttach:name=MyAppName
  3. Tell the debugger where the sources are, Show list of threads, suspend the threads, display call stack, and step through code
$ bin/jdb -connect com.sun.jdi.SharedMemoryAttach:name=MyAppName

Run this command to do this:

  1. kill -QUIT <pid> or kill -3 <pid>
    You may need to run this command as sudo -u user kill -QUIT <pid> where “user” is the user that the java process is running as.
  2. The thread dump will be sent to where ever the standard output is redirected to. (In tomcat, normally the thread dump will be sent to TOMCAT_HOME/logs/Catalina.out)

    QUIT signal does not actually kill the java process. The thread dump will be sent to the standard output and the process will continue.

    [[code]]czo2OTpcIi1YZGVidWcgLVhydW5qZHdwOnRyYW5zcG9ydD1kdF9zb2NrZXQsc2VydmVyPXksc3VzcGVuZD1uLGFkZHJlc3M9MTA0NFwie1smKiZdfTt7WyYqJl19[[/code]]

    What is the impact when you take thread dump?

    1. The Java process is paused — all threads simply stop dead in their tracks
    2. The Main java process asks each thread in turn to give a complete account of what they’re doing
    3. The thread dump is sent to standard error, or somewhere else, depending on your Java vendor
    4. The Java process is unpaused — all threads simply continue where they left off.
    The Java process usually keeps on running, and the whole process only takes a few seconds. Any activity, even input/output is suspended. After the thread dump has completed, everything returns back to normal, just as if nothing had happened.

GDB Debugger Command

GDB Command Line Arguments:

Starting GDB:

  • gdb <em>name-of-executable</em>
  • gdb -e <em>name-of-executable</em> -c <em>name-of-core-file</em>
  • gdb <em>name-of-executable</em> -pid <em>process-id</em>
    (Use ps -auxw to list process id’s.)

Command line options: (version 6. Older versions use a single “-”)

Option Description
–help
-h
List command line arguments
–exec=file-name
-e file-name
Identify executable associated with core file.
–core=name-of-core-file
-c name-of-core-file
Specify core file.
–command=command-file
-x command-file
File listing GDB commands to perform. Good for automating set-up.
–directory=directory
-d directory
Add directory to the path to search for source files.
–cd=directory Run GDB using specified directory as the current working directory.
–nx
-n
Do not execute commands from ~/.gdbinit initialization file. Default is to look at this file and execute the list of commands.
–batch -x command-file Run in batch (not interactive) mode. Execute commands from file. Requires -x option.
–symbols=file-name
-s file-name
Read symbol table from file file.
–write Enable writing into executable and core files.
–quiet
-q
Do not print the introductory and copyright messages.
–tty=device Specify device for running program’s standard input and output.
–pid=process-id
-p process-id
-c process-id
Specify process ID number to attach to.

GDB Commands:

Commands used within GDB:

Command Description
help List gdb command topics.
help topic-classes List gdb command within class.
help command Command description.
apropos search-word Search for commands and command topics containing search-word.
info args
i args
List program command line arguments
info breakpoints List breakpoints
info break List breakpoint numbers.
info break breakpoint-number List info about specific breakpoint.
info watchpoints List breakpoints
info registers List registers in use
info threads List threads in use
info set List set-able option
Break and Watch
break funtion-name
break line-number
break<em>ClassName::functionName</em>
Suspend program at specified function of line number.
break +offset
break -offset
Set a breakpoint specified number of lines forward or back from the position at which execution stopped.
break filename:function Don’t specify path, just the file name and function name.
break filename:line-number Don’t specify path, just the file name and line number.
break <em>Directory/Path/filename</em>.cpp:62
break *address Suspend processing at an instruction address. Used when you do not have source.
break line-number ifcondition Where condition is an expression. i.e. x > 5
Suspend when boolean expression is true.
break line thread thread-number Break in thread at specified line number. Use info threads to display thread numbers.
tbreak Temporary break. Break once only. Break is then removed. See “break” above for options.
watch condition Suspend processing when condition is met. i.e. x > 5
clear
clear function
clear line-number
Delete breakpoints as identified by command option.
delete
d
Delete all breakpoints, watchpoints, or catchpoints.
delete breakpoint-number
delete range
Delete the breakpoints, watchpoints, or catchpoints of the breakpoint ranges specified as arguments.
disable breakpoint-number-or-range
enable breakpoint-number-or-range
Does not delete breakpoints. Just enables/disables them.
Example:
Show breakpoints: info break
Disable: disable 2-9
enable breakpoint-numberonce Enables once
continue
c
Continue executing until next break point/watchpoint.
continue number Continue but ignore current breakpoint number times. Usefull for breakpoints within a loop.
finish Continue to end of function.
Line Execution
step
s
step number-of-steps-to-perform
Step to next line of code. Will step into a function.
next
n
next number
Execute next line of code. Will not enter functions.
until
until line-number
Continue processing until you reacha aspecified line number. Also: function name, address, filename:function or filename:line-number.
stepi
si
nexti
ni
step/next assembly/processor instruction.
info signals
info handle
handle SIGNAL-NAMEoption
Perform the following option when signal recieved: nostop, stop, print, noprint, pass/noignore or nopass/ignore
where Shows current line number and which function you are in.
Stack
backtrace
bt
bt inner-function-nesting-depth
bt -outer-function-nesting-depth
Show trace of where you are currently. Which functions you are in. Prints stack backtrace.
backtrace full Print values of local variables.
frame number
number
Select frame number.
up number
down number
Move up/down the specified number of frames in the stack.
info frame List address, language, address of arguments/local variables and which registers were saved in frame.
info args
info locals
info catch
Info arguments of selected frame, local variables and exception handlers.
Source Code
list
l
list line-number
list function
list -
list start#,end#
list filename:function
List source code.
set listsize count
show listsize
Number of lines listed when list command given.
directory directory-name
dir directory-name
show directories
Add specified directory to front of source code path.
directory Clear sourcepath when nothing specified.
Examine Variables
print variable-name
variable-name
file-name::variable-name
p ‘file-name‘::variable-name
Print value stored in variable.
p *array-variable@length Print first # values of array specified by length. Good for pointers to dynamicaly allocated memory.
p/x variable Print as integer variable in hex.
p/d variable Print variable as a signed integer.
p/u variable Print variable as a un-signed integer.
p/o variable Print variable as a octal.
p/t variable
x/b address
x/b &variable
Print as integer value in binary. (1 byte/8bits)
p/c variable Print integer as character.
p/f variable Print variable as floating point number.
p/a variable Print as a hex address.
x/w address
x/4b &variable
Print binary representation of 4 bytes (1 32 bit word) of memory pointed to by address.
GDB Modes
set gdb-option value Set a GDB option
set logging on
set logging off
show logging
set logging file log-file
Turn on/off logging. Default name of file is gdb.txt
set print array on
set print array off
show print array
Default is off. Convient readable format for arrays turned on/off.
set print array-indexes on
set print array-indexes off
show print array-indexes
Default off. Print index of array elements.
set print pretty on
set print pretty off
show print pretty
Format printing of C structures.
set print union on
set print union off
show print union
Default is on. Print C unions.
set print demangle on
set print demangle off
show print demangle
Default on. Controls printing of C++ names.
Start and Stop
run
r
run command-line-arguments
run < infile > outfile
Start program execution from the beginning of the program. The command break main will get you started. Also allows basic I/O redirection.
continue
c
Continue execution to next break point.
kill Stop program execution.
quit
q
Exit GDB debugger.

GDB Operation:
  • Compile with the “-g” option (for most GNU and Intel compilers) which generates added information in the object code so the debugger can match a line of source code with the step of execution.
  • Do not use compiler optimization directive such as “-O” or “-O2″ which rearrange computing operations to gain speed as this reordering will not match the order of execution in the source code and it may be impossible to follow.
  • control+c: Stop execution. It can stop program anywhere, in your source or a C library or anywhere.
  • To execute a shell command: ! <em>command</em>
    or shell <em>command</em>
  • GDB command completion: Use TAB key
    info bre + TAB will complete the command resulting in info breakpoints
    Press TAB twice to see all available options if more than one option is available or type “M-?” + RETURN.
  • GDB command abreviation:
    info bre + RETURN will work as bre is a valid abreviation for breakpoints

De-Referencing STL Containers:

Use the following commands provided by the script:

Data type GDB command
std::vector<T> pvector stl_variable
std::list<T> plist stl_variable T
std::map<T,T> pmap stl_variable
std::multimap<T,T> pmap stl_variable
std::set<T> pset stl_variable T
std::multiset<T> pset stl_variable
std::deque<T> pdequeue stl_variable
std::stack<T> pstack stl_variable
std::queue<T> pqueue stl_variable
std::priority_queue<T> ppqueue stl_variable
std::bitset<n>td> pbitset stl_variable
std::string pstring stl_variable
std::widestring pwstring stl_variable

Where T refers to native C++ data types. While classes and other STL data types will work with the STL container classes, this de-reference tool may not handle non-native type

Your Ad Here

Performance monitoring in Solaris

Your Ad Here Summary: adb dtrace iostat kmdb mdb mpstat netstat nfsstat p-commands sar vmstat How to Check CPU Utilization (sar -u) Use the sar -u command to display CPU utilization statistics. $ sar -u 00:00:00 %usr %sys %wio %idle 01:00:00 0 0 0 100 The sar command without any options is equivalent to the sar -u command. At any given moment, the processor is either busy or idle. When busy, the processor is in either user mode or system mode. When idle, the processor is either waiting for I/O completion or “sitting still” with no work to do. The following list describes output from the -u option: %usr Lists the percentage of time that the processor is in user mode. %sys Lists the percentage of time that the processor is in system mode. %wio Lists the percentage of time that the processor is idle and waiting for I/O completion. %idle Lists the percentage of time that the processor is idle and not waiting for I/O. A high %wio value generally means that a disk slowdown has occurred. Memory usage : vmstat 5 - Llook at memory/free field and page/sr field. Ignore the first line output as it’s historical procs memory page disk faults cpu r b w swap free re mf pi po fr de sr s0 s1 s6 s3 in sy cs us sy id 0 0 83 4456 456 1 431 266 70 167 0 35 6 6 0 2 523 567 31 14 9 76 0 0 62 3588464 46824 0 196 64 0 0 0 0 5 4 0 0 606 9743 882 86 7 7 0 0 62 3587960 42672 1 552 41 1 1 0 0 2 2 0 0 789 5488 1040 84 7 9 0 1 62 3584704 38848 0 471 3 38 38 0 0 5 5 0 1 1426 5270 968 64 9 27 0 0 62 3586464 38456 0 451 0 0 0 0 0 2 2 0 0 929 6039 1265 70 6 24 Also make sure that cpu/us is at least double cpu/sy mpstat 5 (or iostat -c 5 ) CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 221 3 544 227 75 582 61 31 28 7 267 18 12 2 68 2 209 2 446 395 178 328 37 31 32 6 299 11 7 2 80 -look at the wt field, this is wait-for-I/O which can be network or disk I/O, and should not be more than 30-40 (percent) To see individual disk performance and find slow (‘hot’) disks : iostat -d 5 sd0 sd1 sd6 sd37 kps tps serv kps tps serv kps tps serv kps tps serv 123 6 44 123 6 42 0 0 42 66 2 8 33 1 3 37 1 1 0 0 0 3 0 5 -check the serv column for each disk: this is the disk service time inmilliseconds. However iostat by default shows only the first four disks: if you have more use -x and/or -l options : iostat -xdnl 7 5 (e.g. if you have seven harddisks) extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.4 1.6 3.2 70.4 0.0 0.0 0.0 2.7 0 1 c0t0d0 0.2 1.6 1.6 70.4 0.0 0.0 0.0 3.0 0 1 c0t1d0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c0t6d0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t8d0 88.8 19.8 1276.8 158.4 0.0 0.6 0.0 5.7 0 51 c1t9d0 0.0 0.4 0.0 100.8 0.0 0.0 0.0 17.4 0 1 c1t10d0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t11d0 Your Ad Here