In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use RxJava". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use RxJava.
One of the preparations: log
This poem will observe the execution of the code by printing a log, and will print the time and execution thread, which is in the way of slf4j+log4j.
After the project is created, the structure is as follows:
Please note the location of the log4j.propertieds file. It needs to be placed in the red box in the image above.
To print the current thread in the log, the configuration of log4j is shown in the green box above.% t represents the current thread and% r indicates the time that the program has been executed.
In the pom file, the dependency on the log is:
Part II of org.slf4j slf4j-log4j12 1.8.0-alpha2 preparation: unit testing
The verification code is implemented through the unit test, which is dependent on the unit test in the pom.xml file:
Junit junit 3.8.1 test
The unit test code is located in the red box below:
Preparation part 3: support lambda
Support for lambda expressions is shown in two aspects: maven support and intellij idea tool support. For specific settings, please see "set Intellij idea and maven to support lambda expressions".
The preparatory work is over and can be officially developed.
Dependent library of RxJava
Version 1.0.10 is selected for the dependent library, as follows:
Io.reactivex rxjava 1.0.10 simplest implementation of the Observer pattern
In the first example, we practice the simplest usage:
Create the App.java class and declare the log service:
Public class App {private static final Logger logger = LoggerFactory.getLogger (App.class)
Develop the doExecute method to implement the Rxjava-based observer pattern:
Public void doExecute () {logger.debug ("start doExecute") / / declare an observer in response to the event Observer observer = new Observer () {/ * when the observer publishes the end event, the method will be called * / public void onCompleted () {logger.debug ("start onCompleted") The method will be called * / public void onError (Throwable throwable) {logger.debug ("start onError:" + throwable) when an exception occurs during the event released by the observer and during the observer handling the event. After the observer publishes the event, the method will be called * @ param s * / public void onNext (String s) {logger.debug ("start onNext [" + s + "]");}} Observable observable = Observable.create (new Observable.OnSubscribe () {public void call (Subscriber)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.