Wednesday, August 20, 2014

Two threads in a synchronized block at the same time .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.hello;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gagandsi
 */
public class Hello {
    
    
    public   synchronized void method( String s){
        if (s.equals("1")){
            try {
                System.out.println("this : " + this + " : "+ s);
                Thread.currentThread().yield();
                this.wait(1000);
                System.out.println("This is " + s + " again");
            } catch (InterruptedException ex) {
                Logger.getLogger(Hello.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else {
            System.out.println("This is  " + s);
        }
    }
    

    public static void main(String[] args) {
        try {
            Hello one = new Hello();
            Thread t = new Thread(){

                @Override
                public void run() {
                    super.run(); 
                    one.method("1");
                }
            
        } ;
            
            Thread t2 = new Thread(){

                @Override
                public void run() {
                    super.run(); 
                    one.method("2");
                }
            
        } ;
            t.start();
            t2.start();
        } finally {
        }

    }
}

Wednesday, August 13, 2014

Simple countdownlatch with callable example

 package com.cisco.my;  
 import java.util.ArrayList;  
 import java.util.concurrent.Callable;  
 import java.util.concurrent.CountDownLatch;  
 import java.util.concurrent.ExecutorService;  
 import java.util.concurrent.Executors;  
 import java.util.concurrent.Future;  
 class MyJob implements Callable<String> {  
      CountDownLatch latch;  
      String threadName;  
      String job;  
      public MyJob(CountDownLatch latch, String threadName, String job) {  
           super();  
           this.latch = latch;  
           this.threadName = threadName;  
           this.job = job;  
      }  
      @Override  
      public String call() throws Exception {  
           // TODO Auto-generated method stub  
           System.out.println(threadName + " Going to sleep");  
           Thread.sleep(5000);  
           System.out.println(threadName + " Awake to sleep");  
           latch.countDown();  
           return job.split(" ")[0];  
      }  
 }  
 public class CountdownLatchExample {  
      private static CountDownLatch latch = new CountDownLatch(10);  
      public static void main(String[] args) {  
           ExecutorService service = Executors.newFixedThreadPool(10);  
           ArrayList<Future<String>> x = new ArrayList<Future<String>>();  
           for (int i = 0; i < 10; i++) {  
                Future<String> fut = service.submit(new MyJob(latch, "Thread " + i,  
                          "Random String to process"));  
                x.add(fut);  
           }  
           try {  
                latch.await();  
           } catch (InterruptedException e) {  
                e.printStackTrace();  
           }  
      }  
 }  

Friday, August 8, 2014

org.neo4j.kernel.impl.nioneo.store.UnderlyingStorageException: Unable to load position[25] @[625]


I was getting the following exception in my neo4j code.


org.neo4j.kernel.impl.nioneo.store.UnderlyingStorageException: Unable to load position[25] @[625]
at org.neo4j.kernel.impl.nioneo.store.PersistenceRow.readFullWindow(PersistenceRow.java:162) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.store.PersistenceRow$State$1.transition(PersistenceRow.java:114) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.store.PersistenceRow.lock(PersistenceRow.java:58) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.store.PersistenceWindowPool.acquire(PersistenceWindowPool.java:197) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.acquireWindow(CommonAbstractStore.java:436) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.store.RelationshipGroupStore.getRecord(RelationshipGroupStore.java:58) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.Loaders$4.load(Loaders.java:166) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.Loaders$4.load(Loaders.java:156) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.RecordChanges.getOrLoad(RecordChanges.java:64) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.RecordChanges.getOrLoad(RecordChanges.java:41) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.RelationshipGroupGetter.getRelationshipGroup(RelationshipGroupGetter.java:45) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.RelationshipGroupGetter.getOrCreateRelationshipGroup(RelationshipGroupGetter.java:67) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.RelationshipCreator.connectRelationshipToDenseNode(RelationshipCreator.java:176) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.RelationshipCreator.connectRelationship(RelationshipCreator.java:159) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.RelationshipCreator.relationshipCreate(RelationshipCreator.java:88) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreTransactionContext.relationshipCreate(NeoStoreTransactionContext.java:89) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreTransaction.relationshipCreate(NeoStoreTransaction.java:827) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.relationshipCreate(StateHandlingStatementOperations.java:115) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations.relationshipCreate(ConstraintEnforcingEntityOperations.java:153) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.api.LockingStatementOperations.relationshipCreate(LockingStatementOperations.java:216) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.api.OperationsFacade.relationshipCreate(OperationsFacade.java:515) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.kernel.impl.core.NodeProxy.createRelationshipTo(NodeProxy.java:455) ~[neo4j-kernel-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.spi.v2_1.TransactionBoundQueryContext.createRelationship(TransactionBoundQueryContext.scala:100) ~[neo4j-cypher-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.spi.DelegatingQueryContext.createRelationship(DelegatingQueryContext.scala:45) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.spi.ExceptionTranslatingQueryContext.org$neo4j$cypher$internal$compiler$v2_1$spi$ExceptionTranslatingQueryContext$$super$createRelationship(ExceptionTranslatingQueryContext.scala:41) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.spi.ExceptionTranslatingQueryContext$$anonfun$createRelationship$1.apply(ExceptionTranslatingQueryContext.scala:41) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.spi.ExceptionTranslatingQueryContext$$anonfun$createRelationship$1.apply(ExceptionTranslatingQueryContext.scala:41) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.spi.ExceptionTranslatingQueryContext.org$neo4j$cypher$internal$compiler$v2_1$spi$ExceptionTranslatingQueryContext$$translateException(ExceptionTranslatingQueryContext.scala:149) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.spi.ExceptionTranslatingQueryContext.createRelationship(ExceptionTranslatingQueryContext.scala:41) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.spi.UpdateCountingQueryContext.createRelationship(UpdateCountingQueryContext.scala:73) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.mutation.CreateRelationship.exec(CreateRelationship.scala:77) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergePatternAction$$anonfun$1.apply(MergePatternAction.scala:78) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergePatternAction$$anonfun$1.apply(MergePatternAction.scala:77) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111) ~[scala-library-2.10.4.jar:na]
at scala.collection.immutable.List.foldLeft(List.scala:84) ~[scala-library-2.10.4.jar:na]
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergePatternAction.createThePattern(MergePatternAction.scala:77) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergePatternAction.exec(MergePatternAction.scala:57) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPipe.org$neo4j$cypher$internal$compiler$v2_1$pipes$ExecuteUpdateCommandsPipe$$exec(ExecuteUpdateCommandsPipe.scala:55) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPi$$$$1019fdff8b266d7d9d5647386930b3d8$$$$ands$1$$anonfun$apply$2.apply(ExecuteUpdateCommandsPipe.scala:44) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPi$$$$1019fdff8b266d7d9d5647386930b3d8$$$$ands$1$$anonfun$apply$2.apply(ExecuteUpdateCommandsPipe.scala:44) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371) ~[scala-library-2.10.4.jar:na]
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371) ~[scala-library-2.10.4.jar:na]
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327) ~[scala-library-2.10.4.jar:na]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply$mcZ$sp(ClosingIterator.scala:37) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:34) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:34) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$failIfThrows$1.apply(ClosingIterator.scala:93) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.decoratedCypherException(ClosingIterator.scala:102) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.failIfThrows(ClosingIterator.scala:91) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.hasNext(ClosingIterator.scala:34) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at scala.collection.Iterator$class.foreach(Iterator.scala:727) ~[scala-library-2.10.4.jar:na]
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.foreach(ClosingIterator.scala:28) ~[neo4j-cypher-compiler-2.1-2.1.2.jar:2.1.2]
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48) ~[scala-library-2.10.4.jar:na]
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:176) ~[scala-library-2.10.4.jar:na]
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45) ~[scala-library-2.10.4.jar:na]

Friday, August 1, 2014

Chrome Extension location

~/Library/Application Support/Google/Chrome/Default/Extensions

Friday, July 4, 2014

USB device drawing too much power has been disabled.

I got an error while connecting my nexus tab to macbook pro. I solved this problem by using a different cable to connect. Hope this helps someone.

Tuesday, July 1, 2014

Setting JAVA path on MAC OS


export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
GAGANDSI-M-D04T:bin gagandsi$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    1.8.0_05, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
    1.6.0_65-b14-462, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
To use 1.6 jdk use below command
/usr/libexec/java_home -v 1.6

Saturday, June 28, 2014

Using PS & JStack to map linux threads to java methods on Linux




    1. Display all currently available Java threads:
      ps -C java -L -o pid,tid,nlwp,pcpu,cputime,psr,pmem --sort pcpu

      • pid - process id (the one of the JVM)
      • tid/lwp - thread id / light weight process
      • nlwp - total number of threads in the process
      • pcpu - cpu utilization
      • cputime - accumulated CPU time, user + system
      • psr - processor that thread is currently assigned to
      • pmem - ratio of the process's resident set size to the physical memory on the machine


    1. Identify the threads that, e.g., utilize most the CPU

    1. Convert their linux thread id (TID) to hexadecimal and note it down

    1. Use JStack to get the stack traces of all threads that belong to the Java process
      jstack |less

  1. The nid of each stack trace represents the hexadecimal value of linux thread id (TID)

Squeezing white space in Linux Bash

http://www.linuxjournal.com/article/2563
For instance, we can squeeze all standard white space to a single space by specifying:
tr -s   \n [ *]
This will remove all spaces ...
echo " test test test " | tr -d ' '
so this results in
testtesttest
This will remove leading spaces...
echo " test test test " | sed 's/^ *//'
which results in
test test test
This will remove both trailing and leading spaces
echo " test test test " | sed -e 's/^ *//' -e 's/ *$//'
which results in
test test test
 
echo "   lol  " | xargs
Xargs will do the trimming for you, it's one command/program, no parameters, returns the trimmed string, easy as that!
WARNING:
echo " test    test " | xargs
gives
test test
not
 test    test
  
  
 var1=$(echo $STR | cut -f1 -d-)
var2=$(echo $STR | cut -f2 -d-)

Finding Limits for a Linux Process

cat /proc//limits

Tuesday, April 29, 2014

Making NTFS Drive writeable in MAC

All i had to do is the following :

brew update
brew upgrade osxfuse
brew upgrade ntfs-3g
sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.orig
sudo ln -s /usr/local/sbin/mount_ntfs /sbin/mount_ntfs
brew info osxfuse
You should now be given two lines of instructions specific for your version for installing osxfuse. Cut and paste these from your output. Example below.
sudo /bin/cp -RfX /usr/local/Cellar/osxfuse/2.6.2/Library/Filesystems/osxfusefs.fs /Library/Filesystems
sudo chmod +s /Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs
Re-attach your ntfs drive. If it doesn't work, detach and re-attach the drive one more time…

Links:

Thursday, April 24, 2014

paramiko pexpect setup in mac

To install paramiko on mac . You will have to give the following command


sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install PyCrypto


 sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install paramiko

OR
WITH easy_install you can do something like below

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future  easy_install pycrypto





http://stackoverflow.com/questions/19623267/importerror-no-module-named-crypto-cipher
http://kaspermunck.github.io/2014/03/fixing-clang-error/



http://jessenoller.com/blog/2009/02/05/ssh-programming-with-paramiko-completely-different


cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -Wall -Wstrict-prototypes -Wshorten-64-to-32 -fwrapv -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/MD2.c -o build/temp.macosx-10.9-intel-2.7/src/MD2.o

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

error: command 'cc' failed with exit status 1


Tuesday, March 11, 2014

Thursday, February 6, 2014

Challenge 1: Deviation
Given an array of integer elements and an integer d please consider all the sequences of d consecutive elements in the array. For each sequence we compute the difference between the maximum and the minimum value of the elements in that sequence and name it the deviation.
Your task is to
·         write a function that computes the maximum value among the deviations of all the sequences considered above
·         print the value the standard output (stdout)
Note that your function will receive the following arguments:
·         v
o    which is the array of integers
·         d
o    which is an integer value giving the length of the sequences
Data constraints
·         the array will contain up to 100,000 elements
·         all the elements in the array are integer numbers in the following range: [1, 231 -1]
·         the value of d will not exceed the length of the given array
Efficiency constraints
·         your function is expected to print the result in less than 2 seconds
Example
Input
Output
v: 6, 9, 4, 7, 4, 1
d: 3
6
Explanation
The sequences of length 3 are:
·         6 9 4 having the median 5 (the minimum value in the sequence is 4 and the maximum is 9)
·         9 4 7 having the median 5 (the minimum value in the sequence is 4 and the maximum is 9)
·         7 4 1 having the median 6 (the minimum value in the sequence is 1 and the maximum is 7)

·         The maximum value among all medians is 6




package com.my.hired;

import java.util.Random;

public class MyClass {

 public static void main(String[] args) {
  Integer[] xx = new Integer[100000];
  Random generator = new Random();
  for (int i = 0; i < xx.length; i++) {

   xx[i] = generator.nextInt(100);

  }
  find_deviation(xx, 3);

 }

 public static void find_deviation(Integer[] v, Integer d) {
  long start = System.currentTimeMillis();
  int finalArrayCount = 0;
  for (int count = 0; count < v.length; count++) {
   int min = 2147483647;
   int max = 1;
   for (int j = count; j < count + d; j++) {

    if (count + d > v.length) {
     break;
    }
    if (v[j] > max) {
     max = v[j];
    }
    if (v[j] < min) {
     min = v[j];
    }

   }
   if (finalArrayCount < (max - min)) {
    finalArrayCount = max - min;
   }

  }
  System.out.println(finalArrayCount);
  System.out.println((System.currentTimeMillis() - start) / 1000);

 }
}

Sunday, January 12, 2014

Enable Debug mechanism in Pro*C

In order to use this debug mechanism the Pro*C to be debugged must include the
following libraries:
- oracle library (oracle.pc) – from this library the program must use the LOGON
function to perform the login in the database.
- restart and recovery libraries (restart.pc or the retek_2.pc) – from this library the
program must use the restart_init, restart_file_init, restart_commit,
restart_file_commit and restart_close functions (if using the restart.pc) or the
retek_init, retek_commit and retek_close functions (if using the retek_2.pc) to
perform the commits and rollbacks in the database.
No other functions should be used to perform the login and the database commits.

To run the Pro*C in debug mode the user only needs to append the desired debug
parameters to the command line.

#Run in normal mode
$BIN/pro_c_name $MMUSER/$MMPASS

#Run in debug mode
$BIN/pro_c_name $MMUSER/$MMPASS

RMS allows the user to use six different debug parameters (RMS9 only support the first
three):
- SQL_TRACE=
- TIMED_STATISTICS=
- NO_COMMIT=
- PROFILER=
- RTK_TEST=
- TEST_CASE=

All these parameters support the following values: 0 or FALSE, 1 or TRUE, and some of
them support additional values.
If the user doesn’t want to use a specific debug parameter he can omit the parameter or
use the parameter with the values 0 or FALSE.


And please remember…
Always write the debug flags after the Pro*C parameters, as the Pro*c
parameters will be read inside the program as argv[1], argv[2], …


SQL_TRACE

The value of SQL_TRACE disables or enables the SQL trace facility. Setting this parameter
to true provides information on tuning that can be used to improve performance. This
information will be written in the trace file.
Typically oracle only writes in the trace file when one of the Oracle background processes
(such as dbwr, lgwr, pmon, smon and so on) encounter an exception or when an ORA-
00600 error occurs.
When SQL_TRACE is enabled it will record the events associated with the trace level
passed as parameter.

Turn off the SQL_TRACE

To turn off the SQL_TRACE the user can use this parameter with one of the following
values:

, SQL_TRACE=0 or SQL_TRACE=FALSE

This is the same that perform the following command in the database:

ALTER SESSION SET SQL_TRACE=FALSE;

3.1.2 Turn on the SQL_TRACE

To turn on the SQL_TRACE the user can use this parameter with one of the following
values:

SQL_TRACE=1 or SQL_TRACE=TRUE
SQL_TRACE=4
SQL_TRACE=8
SQL_TRACE=12

This is the same that perform the following command in the database:

ALTER SESSION SET EVENTS '10046 trace name context forever, level 1';
ALTER SESSION SET EVENTS '10046 trace name context forever, level 2';
ALTER SESSION SET EVENTS '10046 trace name context forever, level 8';
ALTER SESSION SET EVENTS '10046 trace name context forever, level 12';

The event that will be traced is the event 10046, which is used to trace sql statements.
This is the most important event that can be set, it is functionally equivalent to setting
sql_trace=true. However, it allows outputting extra details by setting the level to one of
the following levels:
1: Standard SQL tracing
4: Level 1 + tracing bind variables
8: Level 1 + tracing wait events
12: Level 4 + Level 8 (SQL tracing, bind variables and wait events)
And please remember…
The trace files will be written into the directory pointed to by the parameter
user_dump_dest. You can query for the value with:
select value from v$parameter where name = 'user_dump_dest';

TIMED_STATISTICS

The value of TIMED_STATISTICS disables or enables Oracle to include timing information
into the sql trace files. Setting this parameter to true provides information on tuning that
you can use to improve performance.

Sunday, January 5, 2014

Producer / Consumer alternate run example

package concurrency;

import java.util.LinkedList;
import java.util.Queue;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class InterThreadCommunicationExample {

    public static void main(String args[]) {
        BasicConfigurator.configure();

        final Queue sharedQ = new LinkedList();

        Thread producer = new Producer(sharedQ);
        Thread consumer = new Consumer(sharedQ);

        producer.start();
        consumer.start();

    }
}

 class Producer extends Thread {
    private static final Logger logger = Logger.getLogger("Producer");
    private final Queue sharedQ;

    public Producer(Queue sharedQ) {
        super("Producer");
        this.sharedQ = sharedQ;
    }

    @Override
    public void run() {

        for (int i = 0; i &lt; 4; i++) {

            synchronized (sharedQ) {
                //waiting condition - wait until Queue is not empty
                while (sharedQ.size() &gt;= 1) {
                    try {
                        logger.debug("Queue is full, waiting");
                        sharedQ.wait();
                    } catch (InterruptedException ex) {
                        logger.error(ex);
                    }
                }
                logger.debug("producing : " + i);
                sharedQ.add(i);
                sharedQ.notify();
            }
        }
    }
}

 class Consumer extends Thread {
    private static final Logger logger = Logger.getLogger("Consumer");
    private final Queue sharedQ;

    public Consumer(Queue sharedQ) {
        super("Consumer");
        this.sharedQ = sharedQ;
    }

    @Override
    public void run() {
        while(true) {

            synchronized (sharedQ) {
                //waiting condition - wait until Queue is not empty
                while (sharedQ.size() == 0) {
                    try {
                        logger.debug("Queue is empty, waiting");
                        sharedQ.wait();
                    } catch (InterruptedException ex) {
                        logger.error(ex);
                    }
                }
               
                Integer number =(Integer) sharedQ.poll();
                logger.debug("consuming : " + number );
                sharedQ.notify();
             
                //termination condition
                if(number == 3){break; }
            }
        }
    }
}