//Single.java
public static Single just(final T item) {
ObjectHelper.requireNonNull(item, "item is null");//校验,忽略
return RxJavaPlugins.onAssembly(new SingleJust(item));//RxJavaPlugins.onAssembly,钩子函数,忽略
}
//SingleJust.java
public final class SingleJust extends Single {
final T value;
public SingleJust(T value) {
this.value = value;
}
@Override
protected void subscribeActual(SingleObserver super T> observer) {
observer.onSubscribe(Disposables.disposed());
observer.onSuccess(value);
}
}
//1.创建被观察者
var 被观察者2 = Single.just("123")
//2.创建观察者
var 观察者2 = object : SingleObserver {
override fun onSuccess(t: String) {
println("test ---> $t")
}
override fun onSubscribe(d: Disposable) {
}
override fun onError(e: Throwable) {
}
}
//3.调用map操作符(创建新的被观察者)
var 被观察者3 = 被观察者2
.map { it -> "$it ---> 操作符原理" } //分析4
//4.<被观察者3>调用订阅方法
被观察者3.subscribe(观察者2) //位置5
看一下分析4的源码
public final Single map(Function super T, ? extends R> mapper) {
ObjectHelper.requireNonNull(mapper, "mapper is null");
return RxJavaPlugins.onAssembly(new SingleMap(this, mapper)); //分析5
}
public final class SingleMap extends Single {
final SingleSource extends T> source;
final Function super T, ? extends R> mapper;
public SingleMap(SingleSource extends T> source, Function super T, ? extends R> mapper) {
this.source = source;
this.mapper = mapper;
}
@Override
protected void subscribeActual(final SingleObserver super R> t) {
//分析6
source.subscribe(new MapSingleObserver(t, mapper));
}
static final class MapSingleObserver implements SingleObserver {
final SingleObserver super R> t;
final Function super T, ? extends R> mapper;
MapSingleObserver(SingleObserver super R> t, Function super T, ? extends R> mapper) {
this.t = t;
this.mapper = mapper;
}
@Override
public void onSubscribe(Disposable d) {
t.onSubscribe(d);//位置7
}
@Override
public void onSuccess(T value) {
R v;
try {
v = ObjectHelper.requireNonNull(mapper.apply(value), "The mapper function returned a null value.");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
onError(e);
return;
}
t.onSuccess(v);//位置8
}
@Override
public void onError(Throwable e) {
t.onError(e);
}
}
}
Single.just("123").map { it -> "$it ---> 操作符原理" }
.subscribeOn(Schedulers.io())//分析9
.observeOn(AndroidSchedulers.mainThread())//分析10
.subscribe(object : SingleObserver {
override fun onSuccess(t: String) {
}
override fun onSubscribe(d: Disposable) {
}
override fun onError(e: Throwable) {
}
})
查看分析9的源码
//Single.java
public final Single subscribeOn(final Scheduler scheduler) {
ObjectHelper.requireNonNull(scheduler, "scheduler is null");
return RxJavaPlugins.onAssembly(new SingleSubscribeOn(this, scheduler)); //分析11
}
查看分析11的源码
//SingleSubscribeOn.java
public final class SingleSubscribeOn extends Single {
final SingleSource extends T> source;
final Scheduler scheduler;
public SingleSubscribeOn(SingleSource extends T> source, Scheduler scheduler) {
this.source = source;
this.scheduler = scheduler;
}
@Override
protected void subscribeActual(final SingleObserver super T> observer) {
final SubscribeOnObserver parent = new SubscribeOnObserver(observer, source);
observer.onSubscribe(parent);
Disposable f = scheduler.scheduleDirect(parent);//分析12
parent.task.replace(f);
}
static final class SubscribeOnObserver
extends AtomicReference
implements SingleObserver, Disposable, Runnable {
//...
public void run() {
source.subscribe(this);
}
}
}
查看分析12的源码
//抽象类 Scheduler.java
public Disposable scheduleDirect(@NonNull Runnable run) {
return scheduleDirect(run, 0L, TimeUnit.NANOSECONDS);//分析13
}
//分析13的源码
public Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) {
final Worker w = createWorker();//分析14
final Runnable decoratedRun = RxJavaPlugins.onSchedule(run);//钩子函数,忽略
DisposeTask task = new DisposeTask(decoratedRun, w);//位置15
w.schedule(task, delay, unit);//分析16
return task;
}
查看分析14的源码
public abstract Worker createWorker();
//会执行其子类的createWorker,具体的是IoScheduler类的createWorker方法,因为在调用subscribeOn(Schedulers.io())时传入了Schedulers.io(),而通过分析Schedulers.io()就可以知道。
分析Schedulers.io()
//Schedulers.java
public static Scheduler io() {
return RxJavaPlugins.onIoScheduler(IO);//忽略钩子函数,查看IO即可
}
static {
//...
IO = RxJavaPlugins.initIoScheduler(new IOTask());//忽略钩子函数,查看IOTask
//...
}
static final class IOTask implements Callable {
@Override
public Scheduler call() throws Exception {
return IoHolder.DEFAULT;
}
}
//查看IoHolder.DEFAULT
static final class IoHolder {
static final Scheduler DEFAULT = new IoScheduler();
}
Annotation: 译为注释或注解
An annotation, in the Java computer programming language, is a form of syntactic metadata that can be added to Java source code. Classes, methods, variables, pa
定义:pageStart 起始页,pageEnd 终止页,pageSize页面容量
oracle分页:
select * from ( select mytable.*,rownum num from (实际传的SQL) where rownum<=pageEnd) where num>=pageStart
sqlServer分页:
 
hello.hessian.MyCar.java
package hessian.pojo;
import java.io.Serializable;
public class MyCar implements Serializable {
private static final long serialVersionUID = 473690540190845543
回顾简单的数据库权限等命令;
解锁用户和锁定用户
alter user scott account lock/unlock;
//system下查看系统中的用户
select * dba_users;
//创建用户名和密码
create user wj identified by wj;
identified by
//授予连接权和建表权
grant connect to
/*
*访问ORACLE
*/
--检索单行数据
--使用标量变量接收数据
DECLARE
v_ename emp.ename%TYPE;
v_sal emp.sal%TYPE;
BEGIN
select ename,sal into v_ename,v_sal
from emp where empno=&no;
dbms_output.pu
public class IncDecThread {
private int j=10;
/*
* 题目:用JAVA写一个多线程程序,写四个线程,其中二个对一个变量加1,另外二个对一个变量减1
* 两个问题:
* 1、线程同步--synchronized
* 2、线程之间如何共享同一个j变量--内部类
*/
public static