Wednesday, June 26, 2013

Download and Install AndroidSDK in Ubuntu 12.04 (Precise Pangolin)

Android SDK is a development environment for the Android mobile operating system which allows you to write applications for Android devices or gain elevated privileges on android devices with the help of third party software.
This brief tutorial is going to show you how to download and install it in Ubuntu 12.04 if you haven’t already done so. To install it, you first need to install Java JDK package or use the openJDK Java alternative that comes with Ubuntu.
In this tutorial, I’m going to be using the openJDK version of Java. To install Oracle Java version, then read this post first.
Objectives:
  • Install AndroidSDK in Ubuntu 12.04 (Precise Pangolin)
  • Enjoy!

To get started, press Ctrl – Alt – T on your keyboard to open the terminal. When it opens, run the commands below to install OpenJDK.
sudo apt-get install openjdk-6-jre openjdk-6-jdk icedtea6-plugin

Next, download AndroidSDK package by running the commands below. At the time of this writing, the current version was r20. Or click this link to download the .tgz archive file.
wget http://dl.google.com/android/android-sdk_r20-linux.tgz

After downloading, run the commands below to extract the downloaded file.
tar -xvzf android-sdk_r20-linux.tgz

After extracting the package, run the command below to change into the tools directory.
cd ~/android-sdk-linux/tools

Finally, run the commands below to begin the installation.
./android
 Install Android updates if there are any available.

android_precise_5

After updating, run the commands below to include AndroidSDK in your path environment.
gedit ~/.bashrc

Then add these lines at the very top of the file and save it.
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools

android_precise_6


Log out and log back in, then type android on the command line to launch the software.
android avd

Build your own phone.

android_precise_7

Tuesday, June 25, 2013

SHORTCUT FOR OPENING THE SYSTEM MONITOR IN UBUNTU

It’s pretty easy to get the familiar key combo Ctrl+Alt+Del to open the System Monitor in Ubuntu, like what you’d be used to in a version or two of Windows. And it’s well worth doing, as it can come in really handy at times, especially if a crashing app is freezing the system, and the only way to stop it is to kill the process in the System Monitor.
But some people have had trouble getting this key combo to work, and others found it no longer worked after an upgrade. There is plenty mention online of it not working with Compiz-Fusion enabled, as it can usurp those key bindings, but I haven’t found this to be the case (even though I’ve been assured that Compiz-Fusion developers assert it shouldn’t work, and it’s strange that it does for me!).
Besides those poor souls who can’t get this combo to stick while desktop effects are on, invariably it seems a setting had been altered during an upgrade, preventing this combo from working as desired. So here’s what to do if you find yourself in this situation:
Go to System > Preferences > Keyboard Shortcuts, and under Action search for “Log out“. Under Shortcut you will see that Ctrl+Alt+Del is assigned to this action (though it probably doesn’t work); click on that shortcut and press Backspace if you want to disable it, or choose another combination (though I recommend disabling it).
Close it and open the Configuration Editor (found in Applications > System Tools). In the left pane navigate to apps > metacity > global_keybindings, and in the right-hand pane search for a “run_command_X” value under Name (where X is between 1 and 12 and it is not used – I just used run_command_1). Double-click its Value and add <Control><Alt>Delete.
Now select keybinding_commands in the left pane, and locate “command_X” (where X is the same number selected in run_command_X option, eg: command_1), and for its Valueenter gnome-system-monitorNote that, at least on my system, this value can be blank without affecting the keybinding, so if you choose you can leave it out and apply it if needed, though it shouldn’t hurt to do so while you’re in the Configuration Editor.
If you don’t have Configuration Editor, open a terminal and paste these two commands:
gconftool-2 -t str --set /apps/metacity/global_keybindings/run_command_9 '<Ctrl><Alt>Delete'
gconftool-2 -t str --set /apps/metacity/keybinding_commands/command_9 'gnome-system-monitor'
Ctrl+Alt+Delete should now open the System Monitor, and you will see your custom keybinding if you go back into Keyboard Shortcuts. If the key combo still doesn’t work, you’ll probably find there is no custom keybinding defined in Keyboard Shortcuts, but you can easily create a Custom Shortcut by clicking the Add button; to define the key combo, click in the Shortcut field (it should say Disabled) and press the actual key combination to record it.

Monday, June 24, 2013

DEADLOCK

We say that a set of processes or threads is deadlocked when each thread is waiting for an event that only another process in the set can cause. Another way to illustrate a deadlock is to build a directed graph whose vertices are threads or processes and whose edges represent the "is-waiting-for" relation. If this graph contains a cycle, the system is deadlocked. Unless the system is designed to recover from deadlocks, a deadlock causes the program or system to hang.

Synchronization deadlocks in Java programs

Deadlocks can occur in Java because the synchronized keyword causes the executing thread to block while waiting for the lock, or monitor, associated with the specified object. Since the thread might already hold locks associated with other objects, two threads could each be waiting for the other to release a lock; in such a case, they will end up waiting forever. The following example shows a set of methods that have the potential for deadlock. Both methods acquire locks on two lock objects, cacheLock and tableLock, before they proceed. In this example, the objects acting as locks are global (static) variables, a common technique for simplifying application-locking behavior by performing locking at a coarser level of granularity:

An example for a deadlock

 public static Object cacheLock = new Object();
  public static Object tableLock = new Object();
  ...
  public void oneMethod() {
    synchronized (cacheLock) {
      synchronized (tableLock) { 
        doSomething();
      }
    }
  }
  public void anotherMethod() {
    synchronized (tableLock) {
      synchronized (cacheLock) { 
        doSomethingElse();
      }
    }
  }

Now, imagine that thread A calls oneMethod() while thread B simultaneously calls anotherMethod(). Imagine further that thread A acquires the lock on cacheLock, and, at the same time, thread B acquires the lock on tableLock. Now the threads are deadlocked: neither thread will give up its lock until it acquires the other lock, but neither will be able to acquire the other lock until the other thread gives it up. When a Java program deadlocks, the deadlocking threads simply wait forever. While other threads might continue running, you will eventually have to kill the program, restart it, and hope that it doesn't deadlock again.