ThreadDemo1.java
class A extends Thread{ public void run(){ for(int i=0;i<10;i++){ try{Thread.sleep(500);}catch(Exception e){} System.out.println(i+" A"); } } } class B extends Thread{ public void run(){ for(int i=0;i<10;i++){ try{Thread.sleep(500);}catch(Exception e){} System.out.println(i+" B"); } } } class ThreadDemo1 { public static void main(String ar[]){ //java.io.Console c=System.console(); //String s=c.readLine("Hello Enter something "); A a1=new A(); B b1=new B(); a1.start(); b1.start(); try{Thread.sleep(5500);}catch(Exception e){} a1.start(); System.out.println("Finished"); } }ThreadDemo2.java
class A implements Runnable{ public void run(){ for(int i=0;i<10;i++){ try{Thread.sleep(500);}catch(Exception e){} System.out.println(i+" A"); } } } class B implements Runnable{ public void run(){ for(int i=0;i<10;i++){ try{Thread.sleep(500);}catch(Exception e){} System.out.println(i+" B"); } } } class ThreadDemo1 { public static void main(String ar[]){ //java.io.Console c=System.console(); //String s=c.readLine("Hello Enter something "); A a1=new A(); B b1=new B(); Thread t1=new Thread(a1); Thread t2=new Thread(b1); t1.start(); t2.start(); System.out.println("Finished"); } }ThreadDemo3.java
class ThreadDemo3 { public static void main(String ar[]){ Thread t=Thread.currentThread(); System.out.println(t); t.setName("MyThread"); System.out.println(t.getName()); t.setPriority(7); System.out.println(t.getPriority()); } }ThreadDemo4.java
class A implements Runnable{ public void run(){ for(int i=0;i<100000;i++){ //try{Thread.sleep(500);}catch(Exception e){} System.out.println(i+" A "+Thread.currentThread().getName()); } } } class B implements Runnable{ public void run(){ for(int i=0;i<100000;i++){ Thread t=Thread.currentThread(); //try{Thread.sleep(500);}catch(Exception e){} System.out.println(" "+i+"B "+t.getName()); } } } class ThreadDemo4 { public static void main(String ar[]){ //java.io.Console c=System.console(); //String s=c.readLine("Hello Enter something "); A a1=new A(); B b1=new B(); Thread t1=new Thread(a1); Thread t2=new Thread(b1); t1.setPriority(4); t2.setPriority(7); t1.setDaemon(true); t2.setDaemon(true); t1.start(); t2.start(); try{Thread.sleep(3000);}catch(Exception e){} System.out.println("Finished"); } }ThreadDemo5.java
class A implements Runnable{ public void run(){ for(int i=0;i<100000;i++){ //try{Thread.sleep(500);}catch(Exception e){} if(i==100){ throw new ArithmeticException("Exception thrown"); } System.out.println(i+" A "+Thread.currentThread().getName()); } } } class B implements Runnable{ public void run(){ for(int i=0;i<100000;i++){ Thread t=Thread.currentThread(); try{ if(i==100){ throw new ArithmeticException("Exception thrown"); } }catch(ArithmeticException e){System.out.println("hi");} //try{Thread.sleep(500);}catch(Exception e){} System.out.println(" "+i+"B "+t.getName()); } } } class ThreadDemo4 { public static void main(String ar[]){ //java.io.Console c=System.console(); //String s=c.readLine("Hello Enter something "); A a1=new A(); B b1=new B(); Thread t1=new Thread(a1); Thread t2=new Thread(b1); t1.setPriority(4); t2.setPriority(7); t1.setDaemon(true); t2.setDaemon(true); t1.start(); t2.start(); try{Thread.sleep(3000);}catch(Exception e){} System.out.println("Finished"); } }ThreadDemo6.java
class Common{ synchronized public void m1(){ System.out.println("Hi"); try{Thread.sleep(500);}catch(Exception e){} System.out.println("Hello"); } } class A implements Runnable{ Common c1; public void run(){ c1.m1(); } } class B implements Runnable{ Common c2; public void run(){ c2.m1(); } } class ThreadDemo4 { public static void main(String ar[]){ A a1=new A(); B b1=new B(); Common c=new Common(); a1.c1=c; b1.c2=c; Thread t1=new Thread(a1); Thread t2=new Thread(b1); t1.start(); t2.start(); } }ThreadDemo7.java
class Common{ public void m1(){ System.out.println("Hi"); try{Thread.sleep(500);}catch(Exception e){} System.out.println("Hello"); } } class A implements Runnable{ Common c1; public void run(){ synchronized(c1){ c1.m1(); } } } class B implements Runnable{ Common c2; public void run(){ synchronized(c2){ c2.m1(); } } } class ThreadDemo7 { public static void main(String ar[]){ A a1=new A(); B b1=new B(); Common c=new Common(); a1.c1=c; b1.c2=c; Thread t1=new Thread(a1); Thread t2=new Thread(b1); t1.start(); t2.start(); } }
HSQLDB is a portable RDBMS implemented in pure java. It can be embedded with your application as well as can be used separately. It is very a small database that supports almost all features of the standard database system. It comes with small jar file that can be found in lib folder. The HSQLDB jar package is located in the /lib directory of the ZIP package and contains several components and programs. Core components of jar file are : HyperSQL RDBMS Engine (HSQLDB), HyperSQL JDBC Driver, Database Manager, and Sql Tool. Installing and Using Download: download latest release of HyperSQL database from http://hsqldb.org website and extract it. You will see following contents. Here "bin" directory contains some batch files those can be used to run a swing based GUI tool. You can use runManagerSwing.bat to connect to database, but database must be on before running it. Directory lib contains File hsqldb.jar . It is the database to be used by you. Running database First
Comments