본문 바로가기
2023년 이전/ReativeX

RxJava, Rxkotlin 관련 CommonUtils와 CommonUtilsk

by JeongUPark 2020. 1. 19.
반응형

RxJava, RxKotlin에서 사용중인 CommonUtils와 CommonUtilsk의 code는 다음과 같습니다.

CommonUtils.java

import java.util.Random;

public class CommonUtils{
    public static long startTime;
    public static void exampleStart(){
        startTime = System.currentTimeMillis();
    }
    public static void exampleComplete(){
        startTime = System.currentTimeMillis();
    }
    public static void sleep(int mills){
        try{
            Thread.sleep(mills);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
    public static String getThreadName() {
        String threadName = Thread.currentThread().getName();
        if (threadName.length() > 30) {
            threadName = threadName.substring(0, 30) + "...";
        }
        return threadName;
    }
    public static void doSomething(){
        try{
            Thread.sleep(new Random().nextInt(100));
        }catch(InterruptedException e){
            e.printStackTrace();
        }
    }
}

CommonUtilsk.kt

import java.util.*

internal object CommonUtilsk {
    var startTime: Long = 0
    fun exampleStart() {
        startTime = System.currentTimeMillis()
    }
    fun exampleComplete() {
        startTime = System.currentTimeMillis()
    }
    fun sleep(mills: Int) {
        try {
            Thread.sleep(mills.toLong())
        } catch (e: InterruptedException) {
            e.printStackTrace()
        }

    }
    fun getThreadName(): String {
        var threadName = Thread.currentThread().name
        if (threadName.length > 30) {
            threadName = threadName.substring(0, 30) + "..."
        }
        return threadName
    }
    fun doSomething(){
        try{
            Thread.sleep(Random().nextInt(100).toLong())
        }catch (e : InterruptedException){
            e.printStackTrace()
        }
    }
}
반응형

'2023년 이전 > ReativeX' 카테고리의 다른 글

RxJava, RxKotlin - skipUntil 함수  (0) 2020.01.19
RxJava, RxKotlin - takeUntil 함수  (0) 2020.01.19
RxJava, RxKotlin - amb 함수  (0) 2020.01.19
RxJava, RxKotlin - Concat 함수  (0) 2020.01.17
RxJava, RxKotlin - merge 함수  (0) 2020.01.17