Comments (6)
@dingdangmao123 整个过程有日志记录每个task等待,执行,结束的时间,贴下log。另外,另外,怎么有效构建完全看业务怎么拆分,库只是一种工具的。最好能表述下你的场景。
from anchors.
var t1 = object: Task("t1", true) {
override fun run(name: String) {
Thread.sleep(500)
Log.i("Tag",name+" "+ (System.currentTimeMillis()-start))
}
}
val map = mapOf<String, Task>("t1" to t1)
val project = Project.Builder("App", Project.TaskFactory(object : TaskCreator {
override fun createTask(taskName: String): Task {
return map[taskName] ?: error("")
}
})).add("t1").build()
AnchorsManager.getInstance()
.debuggable(true)
.addAnchor("t1")
.start(project)
2021-05-07 15:54:08.644 24397-24424/com.example.myapplication I/Tag: t1 563
2021-05-07 15:54:08.676 24397-24397/com.example.myapplication I/Tag: app end 595
2021-05-07 15:54:08.820 24397-24430/com.example.myapplication I/Tag: MainActivity
只添加了一个任务
from anchors.
贴一下库内部的log,过滤tag就可以拿到,有完整的信息。另外,单个task不需要用project。
from anchors.
2021-05-07 15:54:08.093 24397-24397/com.example.myapplication D/Anchors: App_start(1620374048088) -- onStart --
2021-05-07 15:54:08.107 24397-24397/com.example.myapplication D/Anchors: App_start(1620374048088) -- onRunning --
2021-05-07 15:54:08.107 24397-24397/com.example.myapplication D/Anchors: App_start(1620374048088) -- onFinish --
2021-05-07 15:54:08.115 24397-24397/com.example.myapplication D/Anchors: t1 -- onStart --
2021-05-07 15:54:08.116 24397-24424/com.example.myapplication D/Anchors: t1 -- onRunning --
2021-05-07 15:54:08.117 24397-24397/com.example.myapplication D/Anchors: App_start(1620374048088) -- onRelease --
2021-05-07 15:54:08.645 24397-24424/com.example.myapplication D/Anchors: t1 -- onFinish --
2021-05-07 15:54:08.651 24397-24424/com.example.myapplication D/TASK_DETAIL: TASK_DETAIL
======================= task (t1 ) =======================
| 依赖任务 : App_start(1620374048088)
| 是否是锚点任务 : true
| 线程信息 : Anchors Thread #1
| 开始时刻 : 1620374048115 ms
| 等待运行耗时 : 1 ms
| 运行任务耗时 : 528 ms
| 结束时刻 : 1620374048644
==============================================
2021-05-07 15:54:08.651 24397-24424/com.example.myapplication D/ANCHOR_DETAIL: TASK_DETAIL
======================= task (t1 ) =======================
| 依赖任务 : App_start(1620374048088)
| 是否是锚点任务 : true
| 线程信息 : Anchors Thread #1
| 开始时刻 : 1620374048115 ms
| 等待运行耗时 : 1 ms
| 运行任务耗时 : 528 ms
| 结束时刻 : 1620374048644
==============================================
2021-05-07 15:54:08.651 24397-24424/com.example.myapplication D/Anchors: App_end(1620374048088) -- onStart --
2021-05-07 15:54:08.651 24397-24424/com.example.myapplication D/Anchors: t1 -- onRelease --
2021-05-07 15:54:09.023 24397-24397/com.example.myapplication D/Anchors: App_end(1620374048088) -- onRunning --
2021-05-07 15:54:09.024 24397-24397/com.example.myapplication D/Anchors: App_end(1620374048088) -- onFinish --
2021-05-07 15:54:09.027 24397-24397/com.example.myapplication D/Anchors: App_end(1620374048088) -- onRelease --
from anchors.
另外想请教一个问题 如果Task之间耗时差别比较大 如何构建 整体比较省时 @YummyLau
from anchors.
528ms是正常的,sleep到唤醒到打点。其实要先整理好项目的task哪些是必须阻塞同步完成,哪些可以延后主线程同步,哪些可以异步,然后再排好序执行就行了。框架内部用的是线程调度,不会过多损耗,有的都是系统的线程调度切换。具体来说还是看项目需求。另外,anchor是会同步阻塞调用的,你的demo在异步sleep之后才完成且主线程要同步等待,这些都是系统损耗。
from anchors.
Related Issues (20)
- java.lang.IllegalStateException: rhs must not be null HOT 3
- java.lang.NullPointerException: Attempt to invoke interface method 'void java.lang.Runnable.run()' on a null object reference HOT 8
- 是否有提供类似alpha的onProjectFinish的回调 HOT 2
- 组件化 HOT 3
- java.util.ConcurrentModificationException HOT 4
- 耗时任务超过10秒 HOT 4
- 主线程Sleep 造成ANR HOT 3
- 任务分支 HOT 2
- Sleep 可以改成信号量,防止部分无意义唤醒造成的线程调度开销 HOT 8
- 首次安装耗时10秒以上
- java.lang.IllegalArgumentException HOT 1
- java.lang.RuntimeException: can no run task task-lock again! HOT 1
- 反馈一个问题,从1.1.4升级到1.1.6,在OPPO R9s上出现崩溃。 HOT 2
- Caused by: java.lang.IllegalArgumentException HOT 3
- AnchorsRuntime.kt line 106 com.effective.android.anchors.AnchorsRuntime.tryRunBlockTask$anchors_release
- AnchorThreadPool.kt line 29 com.effective.android.anchors.AnchorThreadPool.<init> HOT 1
- .
- ANR ,AnchorsRuntime.tryRunBlockTask$anchors_release ANR triggered by main thread waiting for too long
- 如果一个ATask内部开启了子线程去执行网络调度,依赖ATask的BTask 是不受 新开的线程是不受阻塞的
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anchors.