LiteGo


Source link: https://github.com/litesuits/android-lite-go

LiteGo??????Android??????

LiteGo?????Java??????????????????????????????????????????????????????????????????????????????? LiteGo??????Runnable?Callable?FutureTask ??????????????????????SmartExecutor??????????App?????????????? ???App??SmartExecutor????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????


?? : litesuits.com

QQ? : 42960650


LiteGo ??

?????????????

  • ??????????????????????????????????Java??????????????
  • ???????App?????????????????????????Doug Lea??java???????????concurrent??
  • ???????????????????????????????????????????????????????????????????????

???????????????????????????????

LiteGo ??

  • ????????????????CPU??????????????????
  • ??????????????CPU??????????????????
  • ???????????????????????????????

???????????????????CPU????????CPU???????????????????????????CPU?????????CPU?????????

?????????????????????????????????????????

LiteGo ??

????????????????????????

????????????????????????????

?????????????????????????????

???????????????????

  • ??????????
  • ??????????
  • ???????
  • ????????????
  • ????????????

LiteGo ??? OK?LET IT GO?

????

// ????????????[?????]??[????]?? SmartExecutor smallExecutor = new SmartExecutor();
  // set temporary parameter just for test // ??????????????????????  // number of concurrent threads at the same time, recommended core size is CPU count // ???????????????????????????? smallExecutor.setCoreSize(2);
  // adjust maximum number of waiting queue size by yourself or based on phone performance // ????????????????????????? smallExecutor.setQueueSize(2);
  // ??????[?????]??????[????]???????????????????????????? smallExecutor.setSchedulePolicy(SchedulePolicy.LastInFirstRun);
  // ???????????[????]????????????????????? smallExecutor.setOverloadPolicy(OverloadPolicy.DiscardOldTaskInQueue);

???????????????2??????????????????2?????????????????????????????????????????????

????????????

// ???? 4 ??? for (int i = 0; i < 4; i++) {

  final int j = i;
  smallExecutor.execute(new Runnable() {

@Override

public void run() {

 HttpLog.i(TAG, " TASK " + j + " is running now ----------->");

 SystemClock.sleep(j * 200);

}

  
}
);
 
}
  // ???1?????????? Future future = smallExecutor.submit(new Runnable() {

  @Override
  public void run() {

HttpLog.i(TAG, " TASK 4 will be canceled... ------------>");

SystemClock.sleep(1000);

  
}
 
}
);
  // ?????????? future.cancel(false);

??????????? 0?1?2?3?4 ???????4?????????????Future???

?????0?1???????????2?3???????????????????4???????????2????????3?4 ?

??4???????????????

TASK 0 is running now -----------> TASK 1 is running now -----------> TASK 3 is running now ----------->

LiteGO ????

??? SmartExecutor ????????

public Future<?> submit(Runnable task)  public <T> Future<T> submit(Runnable task, T result)  public <T> Future<T> submit(Callable<T> task)  public <T> void submit(RunnableFuture<T> task)  public void execute(final Runnable command)

????? execute ???????????????? FutureTask ??? execute ??????? FutureTask ?????? RunnableFuture ????? Runnable ? Future ???????

??????? execute ????

@Override public void execute(final Runnable command) {

  if (command == null) {

return;
  
}

WrappedRunnable scheduler = new WrappedRunnable() {

@Override

public Runnable getRealRunnable() {

 return command;

}

 public Runnable realRunnable;

 @Override

public void run() {

 try {

  command.run();

 
}
 finally {

  scheduleNext(this);

 
}

}

  
}
;

boolean callerRun = false;
  synchronized (lock) {

if (runningList.size() < coreSize) {

 runningList.add(scheduler);

 threadPool.execute(scheduler);

}
 else if (waitingList.size() < queueSize) {

 waitingList.addLast(scheduler);

}
 else {

 switch (overloadPolicy) {

  case DiscardNewTaskInQueue:

waitingList.pollLast();

waitingList.addLast(scheduler);

break;

  case DiscardOldTaskInQueue:

waitingList.pollFirst();

waitingList.addLast(scheduler);

break;

  case CallerRuns:

callerRun = true;

break;

  case DiscardCurrentTask:

break;

  case ThrowExecption:

throw new RuntimeException("Task rejected from lite smart executor. " + command.toString());

  default:

break;

 
}

}

//printThreadPoolInfo();

  
}

  if (callerRun) {

command.run();

  
}
 
}

??????????????

  1. ??????????“??”?????????????????
  2. ???????????????????????
  3. ????????????????????????????????
  4. ???????????????????????????
  5. ??????????????“??”???????????????????????

?????????????????????

Resources

An easy way to check the settings before requesting location using RxJava. Based on Android-ReactiveLocation.

Gradle Script Kotlin provides support for writing Gradle build scripts using JetBrains' Kotlin language. It aims to provide Gradle users with a rich, flexible and statically-typed approach to developing build logic in conjunction with the best IDE and tooling experience possible.

Official Android SDK to support:

  • Ride Request Button
  • Ride Request Widget
  • REST APIs

An ImageView can auto scroll with device rotating.

History Provider is a simple library that stores your typed history inside a Database using the concept of Content providers, making the history database available to any application in the phone.

Android library to make notes drop, visualization for music players.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes