Guest User

Untitled

a guest
May 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. final Handler handler = new Handler();
  2. handler.postDelayed(new Runnable() {
  3. @Override
  4. public void run() {
  5. doSomething();
  6. count++;
  7. if (count <= 3) handler.postDelayed(this, 3000);
  8. }
  9. }, 3000);
  10.  
  11. myApi
  12. .getRequestBody()
  13. .repeatWhen(h-> h.delay(3000L, TimeUnit.MILLISECONDS))
  14. .takeUntil(stopPolling -> count < 3)
  15. .subscribe(this::showList);
  16.  
  17. final Handler h = new Handler();
  18. for (int i=1;i<numberOfTimes+1;i++) {
  19. h.postDelayed(new Runnable() {
  20. @Override
  21. public void run() {
  22. function();
  23. }
  24. },i*3000);
  25. }
  26.  
  27. public static void main(String[] args) {
  28. new Thread() {
  29. @Override
  30. public void run() {
  31. while (true) {
  32. for (int i = 0; i < 3; i++) {
  33. ourMethod();
  34. }
  35.  
  36. try {
  37. Thread.sleep(3000);
  38. } catch (InterruptedException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
  43. }.start();
  44. }
  45.  
  46. public static void ourMethod() {
  47. //do smth
  48. }
Add Comment
Please, Sign In to add comment