Skip to main content

Posts

Showing posts from November, 2013

Runing multiple mysql instances on one machine

Suppose you have two mysql instances  c:\mysq1 and c:\mysql2 1- create file c:\mysql1\my.cnf add the following lines [mysqld] datadir = C:/mysql1/data port = 3308     2- create file c:\mysql2\my.cnf add the following lines   [mysqld] datadir = C:/mysql2/data port = 3309    3-now run the first instance    cd c:\mysql1\bin mysqld --defaults-file=c:\mysql1\my.cnf     4-open another command and run the second instance     cd c:\mysql2\bin mysqld --defaults-file=c:\mysql2\my.cnf finsihed ;)

Java Start/Stop System process and also check if it is running or not

This  block of code detects if mysql  database process  is running or not String line; try {             Process proc = Runtime.getRuntime().exec("wmic.exe");             BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));             OutputStreamWriter oStream = new OutputStreamWriter(proc.getOutputStream());             oStream .write("process where name='mysqld.exe'");             oStream .flush();             oStream .close();             while ((line = input.readLine()) != null) {                 // Here detects if mysqld process is running             }             input.close();         } catch (IOException ioe) {             ioe.printStackTrace();         }   This block of code starts mysql service Process p = new ProcessBuilder("c:/mysql/bin/mysqld", "").start();   And  you may use  p.destroy(); if you want to Stop it 

GIF animation for windows 7

i have created a java program that plays animated images and you can also control the speed by pressing < for  slowing down  or by pressing > for speeding up the animation program attached link http://www.4shared.com/zip/IejwaSBd/GIF.html

understanding "synchronized , wait() and notify() "

// An incorrect implementation of a producer and consumer. class Q { int n; synchronized int get() { System.out.println("Got: " + n); return n; } synchronized void put(int n) { this.n = n; System.out.println("Put: " + n); } } class Producer implements Runnable { Q q; Producer(Q q) { this.q = q; new Thread(this, "Producer").start(); } public void run() { int i = 0; while(true) { q.put(i++); } } } class Consumer implements Runnable { Q q; Consumer(Q q) { this.q = q; new Thread(this, "Consumer").start(); } public void run() { while(true) { q.get(); } } } class PC { public static void main(String args[]) { Q q = new Q(); new Producer(q); new Consumer(q); System.out.println("Press Control-C to stop."); } } Although the put( ) and get( ) methods on Q are synchronized, nothing stops the producer from overrunning the consumer, nor will anything stop the consumer from consuming the same queue value twice. Thus, you get the e

Fast Download with progress indication facility using Java NIO

package test; import java.io.FileOutputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.Date; public class DownloadProgressExample {     public static void main( String[] args ) {         new Downloader( "c:/header12.jpg", "http://www.daralshifa.com/images/mainheader/header12.jpg" );     }     private interface RBCWrapperDelegate {          // The RBCWrapperDelegate receives rbcProgressCallback() messages         // from the read loop.  It is passed the progress as a percentage         // if known, or -1.0 to indicate indeterminate progress.         //         // This callback hangs the read loop so a smart implementation will         // spend the least amount of time possible here before returning.         //         // One possible implementation is to push the progress message         // atomic