Posted on

Loading data from few sources by rxjava

[code language=”java”]
Observable<Data> memory = …;
Observable<Data> disk = …;
Observable<Data> network = …;
// Retrieve the first source with data
Observable<Data> source = Observable
.concat(memory, disk, network)
.first();
[/code]

Save data to cache

[code language=”java”]
Observable<Data> networkWithSave = network.doOnNext(data -> {
saveToDisk(data);
cacheInMemory(data);
});
Observable<Data> diskWithCache = disk.doOnNext(data -> {
cacheInMemory(data);
});
[/code]

Update data

[code language=”java”]
Observable<Data> source = Observable
.concat(memory, diskWithCache, networkWithSave)
.first(data -> data.isUpToDate());
[/code]

Posted on

Java feature

  1. double brace
  2. ThreadLocal
  3. Instance Initializers

    [code language=”java”]
    public class Foo {
    public Foo() {
    System.out.println("constructor called");
    }

    static {
    System.out.println("static initializer called");
    }

    {
    System.out.println("instance initializer called");
    }
    }
    [/code]

  4. Enum – is a class
  5. try, finally, exception

    [code language=”java”]
    public static int f() {
    try {
    throw new RuntimeException();
    } finally {
    return 0;
    }
    }
    [/code]

  6. URL

    [code language=”java”]
    new URL("http://www.yahoo.com").equals(new URL("http://209.191.93.52"))
    [/code]

    =true

Posted on

Multithreading in java

dzone

Multi-threading represents a very intriguing topic, even after years of research and development for high quality, robust, and efficient software. With equal emphasis on hardware improvements and the software that runs on it – we have newer paradigms for parallelism. The most important yet basic concepts are the ones which I present here. I then explain the intricacies of multi-threading in the Java programming language. Some of these are newer features and supported only from the Java Platform Standard Edition 5.0. Let us start with a quick overview and understanding of the core concepts.

Continue reading Multithreading in java