Friday, October 26, 2012

Synchronised Printer in java

Take a guess whats this string trying to convey and match your guess with code output later.
public static String s="ASvhiurkalla";

Well let me put two synchronized writers that would write one character alternatively.

This way we would expect to see Aviral Shukla as  actual output.

 package aiwi.code;  
 public class SyncPrinter {  
      public int index;  
      boolean done = false;  
      synchronized void print2() {  
           if(!done)  
                try {  
                     wait();  
                } catch(InterruptedException e) {  
         Thread.interrupted();  
                }  
           if(index<s.length())  
                System.out.println("\t" + s.charAt(index));  
           done = false;  
           notify();  
      }  
      synchronized void print1(int n) {  
           if(done)  
                try {  
                     wait();  
                } catch(InterruptedException e) {  
                     System.out.println("InterruptedException caught");  
                }  
           if(n<s.length())  
                System.out.println("" + s.charAt(n));  
           this.index = n+1;  
           done = true;  
           notify();  
      }  
      public static String s="ASvhiurkalla";  
      public static void main(String[] args) {  
           SyncPrinter q=new SyncPrinter();  
           new Printer1(q).start();  
           new Printer2(q);  
      }  
 }  
 class Printer1 extends Thread {  
      SyncPrinter q;  
      Printer1(SyncPrinter q) {  
           this.q = q;  
      }  
      public void run() {  
           int i = -2;  
           while(q.index<=SyncPrinter.s.length()) {  
                i=i+2;  
                q.print1(i);  
           }  
      }  
 }  
 class Printer2 extends Thread {  
      SyncPrinter q;  
      Printer2(SyncPrinter q) {  
           this.q = q;  
           new Thread(this, "Printer2").start();  
      }  
      public void run() {  
           while(q.index<=SyncPrinter.s.length()) {  
                q.print2();  
           }  
      }  
 }  


I would hope readers do see the producer consumer aspect of this program.

Thursday, October 25, 2012

Producer consumer thread

A good example for producer consumer problem can be desktop search application. for the producer it s the searcher alias crawler which just visits all the files on given roots or drives. For the consumer we have the storer or the indexer who takes the file and provides easy an quick access to it. For the implementation I guess blocking queue data structure is sufficient with two producer consumer threads.

Sunday, August 15, 2010

Wireframe Sketcher

Today tried with wire frame sketcher some of my observations on same

It s really spoon feeding to use it in eclipse ...one can search eclipse live / youtube for video demo of the same.

Then it really gives cool UI development options on its .screen file.

I am exploring to see more and more usage but its worth giving a try .

I could get a browser with window playing cover flow with different ui widgets depicting image and other controls in less than 5 min.

Some of us can extend the start to reap more benefits out of it.

Monday, November 16, 2009

Customer usage of Eclipse Tools

Recently I read about the Eclipse UDC i.e Usage Data Collector a set of plugins which can help you to analyse what views/bundles etc of the tool is being used , in what manner by the end user.

Besides providing a lot of "Customer Tool Interaction" this mechanism definitely provides a hope to make tools intelligent based on the data being generated by customer activities.

The Eclipse UDC is very easy to use as it comes in Preference page for eclipse and can be configured directly from there.

The Database location can be specified in many different ways depening on what kind of application one is developing.

Looking fwd to see its usage with a combination of Artificial Intelligence where component learn and evolve by operating on the data gathered from customer activity on each one of them.

Monday, October 12, 2009

Evolving Services with Technology

How long does it take to realize we have a huge set of services available for communicating and collaborating with our friends colleagues or just anyone in the world...Let me list down the services that I see

1)E mail
2)Chat
3)Blog
4)Wiki
5)Discussion Forums
6)SMS
7)Social Networking sites ovi twitter facebook orkut etc ..


Quite a few isnt it?

Now lets talk about something like Google Wave ...its an open source google initiative to collaborate the services and make our communication centralised rather than posting things at different places and then trying to realise the connectivity of thoughts.

With Google Wave developers at google have tried to show how to keep evolving services when technology is evolving....More should come from us to take such initiatives with huge global response and make earth a better place!

Saturday, October 10, 2009

Always a developer

Two ways Two views Two right things..

Which way which view to get the which right thing....

Sounding abstract yeah that s how one sounds when confused .Lets look into the Two X's.

Case Way1 (x=1): Do things in a stable work...make sure nothing breaks.

Case Way2(x=2):Keep evolving even if it means to break whatever exists

Case View1: Customers are happy with stable product why do u wanna make them unhappy

Case View2:Excite the customers with new things...can be other way at times too

Case Output1: A stable product that every one likes and trusts ..but can get bored.

Case Output2: A new exciting product make world go crazy ...can turn them mad too.

Wow haven't I quoted things that should be merged and excitement should be built with trust...Its the ability to adjust (way1) and be flexible(way2) .