Tuesday, October 25, 2011

Java Green thread

If the thread is handled by the JVM itself then it is called green thread.
Green thread are used in the following cases
1. Operation systems where multi threading is not supported(eg. Low end Mobile OS)
2. If you are using Java 1.1 or previous versions

Green threads are slow because the JVM has to switch between processes

Wednesday, October 5, 2011

Linux: get time in Indian Standard Time (IST)

On Any linux server, if you want to get time in the Indian standart time zone. use the following command

TZ='Asia/Kolkata' date 

For eg: TZ='Asia/Kolkata' date +%Y%m%d gives you 20111005

This is very useful if your server is on a different timezone and your applicaion(shell script) requires Indian Standard time (IST)

note: TZ=IST does not work since shell interpret it as International Standard Time





Saturday, October 1, 2011

Postgres/MySQL database synchronization using RubyRep



It is nice to have a tool which can synchronize two databases so that if you have two copies of a database then you can convert the old database to the latest one, by synchronizing all the missing data to new database. A synchronization tool makes database A same as database B provided that A and B has the same schema. The tool does this by copying all extra data in A to B and deleting extra data in B. One practical use of such a tool is synchronizing a production database to staging database and vice versa.

Database systems like Oracle comes with built in tools to sync two datbases but postgres and mysql does not have a sync tool in its default package. So if you want to synchronize two postgres databases then you require a third party tool. RubyRep is such a synchronization tool which supports postgres and mysql. As the name indicates it is developed using Ruby language, that means you have to install ruby in your machine to use this tool. It also requires a number of gems (ruby libraries), but wait.... Rubyrep also has a Jruby version, that means you can run it on any machine which has a JVM installed on it and you dont have to install any dependencies. Cool, isn't it? All you have to do is to download it, extract it and use it. Here is the home page of RubyRep

A simple guide to using RubyRep

Rubyrep works on the following concepts....
It has to synchronize two databases; the left database and the right database.By default it synchronizes left database to right database. You have to provide the list of tables which has to be synchronized. Ruby rep assumes that your tables are in public schema. If you have other schemas then you have to provide the schma name also. Rubyrep reads the left and right database connection details and other configurations from a config file. The configuration file has its own syntax.So the best way to create a config file is to allow ruby rep to create a default config file, then edit it with your database details.
  1. Creating a config file
rubyrep create CONFIG_FILE
eg: sh rubyrep create myconf.cfg

  1. Scanning difference between two databases
rubyrep scan -c CONFIG_FILE
eg: sh rubyrep scan -c myconf.cfg

  1. Syncing two databases
rubyrep sync -c CONFIG_FILE
eg:sh rubyrep sync -c myconf.cfg

  1. Overwrting the default configurations
To overwrite the configuration in the config file, pass the configuration parameters as arguements to the rubyrep command
eg: rubyrep sync -c alert_manager.cfg 'vertical_lv',tip
Synchronizes only vertical_lv and tip tables
For more details, visit the rubyrep tutorial page.