Solarex's Blog

我只想过,平平淡淡的生活,欲望啊,请放过脆弱的我

Java Thread Tutorial

| Comments

Java Thread and Multithreading Tutorial

There are two types of threads in an application – user thread and daemon thread. When we start an application, main is the first user thread created and we can create multiple user threads as well as daemon threads. When all the user threads are executed, JVM terminates the program.

We can set different priorities to different Threads but it doesn’t guarantee that higher priority thread will execute first than lower priority thread. Thread scheduler is the part of Operating System implementation and when a Thread is started, it’s execution is controlled by Thread Scheduler and JVM doesn’t have any control on it’s execution.

A Journey on the Android Main Thread

| Comments

When facing bugs that were related to how we interact with the main thread, I decided to get a closer look at what the main thread really is.

1
2
3
4
5
public class BigBang {
  public static void main(String... args) {
    // The Java universe starts here.
  }
}

All Java programs start with a call to a public static void main() method. This is true for Java Desktop programs, JEE servlet containers, and Android applications.

When the Android system boots, it starts a Linux process called ZygoteInit. This process is a Dalvik VM that loads the most common classes of the Android SDK on a thread, and then waits.

Intro to Android Loopers and Handlers

| Comments

What can you do with Loopers and Handlers? Basically, they implement a common concurrency pattern that I call the Pipeline Thread. Here’s how it works:

  • The Pipeline Thread holds a queue of tasks which are just some units of work that can be executed or processed.
  • Other threads can safely push new tasks into the Pipeline Thread’s queue at any time.
  • The Pipeline Thread processes the queued tasks one after another. If there are no tasks queued, it blocks until a task appears in the queue.
  • Sometimes tasks can called messages and other names.

Android反编译

| Comments

有时候在Google Play Store看到一些有趣的应用,或者对有些应用的资源图片之类的很感兴趣,这时候就需要用到Android反编译APK的一些工具了。

Moving Bitbucket Repo to Github

| Comments

1
2
3
4
5
6
git clone https://bitbucket.org/username/repos.git local_dir
cd local_dir
git remote rename origin bitbucket
git remote add origin git@github.com:username/repos.git
git push -u origin master
git remote rm bitbucket