多线程数据流的 UML
我想画一张图,您可以在其中看到 java 程序的数据流,以及是否有一个或多个线程处理数据。
序列图不显示多线程,当您有超过 5 个不同的实体时,序列图会变得非常混乱。
类图很适合显示关系,但缺少数据流。
我想画框(如类/包图)并连接它们。也许有一个加倍的方框,并且中间有 ...
以表明可以有多个线程。
对于这种数据流图,UML 有什么图?
什么编辑器适合该图?如果可能的话,免费软件或开源软件。
I want to paint a diagram where you can see the dataflow of a java program, and if there are one or multiple threads handling the data.
Sequence charts don't show multithreading and get very confusion when you have more than 5 different entities.
Class diagrams are good for showing the relations but the dataflow is missing.
I would like to paint boxes (like class/package diagram) and connect them. Maybe having a box doubled and ...
in between to show that there can be more than one thread.
What diagram does UML have for this kind of dataflow diagram?
What editor is good for that diagram? If possible freeware or open source.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我会查看 UML 活动图来显示多个线程及其并行执行。在通信图上,有时您还会看到线程字母(例如 A、B、C)来尝试表示并发线程,但我几乎总是发现这令人困惑。 UML 2 中的一些片段可能有助于在序列图中显示并发性,但我总是觉得这很麻烦,而且图很难重构(这意味着它们很快就会过时)。
如果线程正在执行相同的任务,但并行运行,您可以在图表中添加注释来解释这一点。这样您就可以专注于准确、干净地对单个线程进行建模。
关于使用哪种工具,大多数 IDE 都会包含一定程度的 UML 建模工具,例如,我很高兴使用 Eclipse 附带的基于 EMF 的工具。
I would look at athe UML activity diagram for showing multiple threads and their parallel execution. On communication diagrams, you also sometimes see thread letters (e.g. A,B,C) to try and denote concurrent threads, but I almost always find this confusing. There are fragments in UML 2 which may help show concurrency in sequence diagrams, but I always find this cumbersome and the diagrams hard to refactor (which means they quickly go out of date).
If the threads are executing the same tasks, but running in parallel, you could just add a Note to your diagram to explain this. This way you could concentrate on modelling a single thread accurately and cleanly.
With regard to which tool to use most IDEs will have some degree of UML modelling tool included e.g. I am happy to use the EMF based tools which ship with Eclipse.
序列图确实有并行操作和异步调用的符号,并且将是显示数据流的适当方法。
Sequence diagrams do have notation for both parallel operations and asynchronous calls and would be an appropriate means of showing your dataflow.
取决于问题,但我可能会用活动图来描述事件的顺序:
http://www.agilemodeling.com/style/activityDiagram.htm
然后可能是一组序列图来捕获每个步骤的类级交互。
或者,您可以查看串行描述序列(考虑在循环中迭代数组),并注意迭代应该在实现中并行化。
Depends on the problem, but I'd probably go with an activity diagram to describe the sequence of events:
http://www.agilemodeling.com/style/activityDiagram.htm
Then maybe a set of sequence diagrams to capture the class-level interactions for each of those steps.
Alternatively, you could look at describing the sequence serially (think iterating an array in a loop) and just note that the iteration should be parallelised in implementation.
为了显示多线程可以使用不同的颜色来显示。
对于前红色显示一个线程
和蓝色来显示不同的线
To show multithreading you can use different colors to show.
For ex red to show one thread
and blue color to show different thread
如果您想可视化多个线程的状态(像许多分析器一样),请查看 PlantUML 时序图< /a>.它不是显示许多线程间通信的理想工具,但非常适合显示线程状态之间的转换:

If you want to visualize multiple threads' states (like many profilers do), take a look at PlantUML timing diagrams. It isn't ideal tool for showing many inter-thread communications but suits well for showing transitions between threads' states:

我会告诉你一些更激进的事情,是的,我同意活动图对于表示并行流确实很有用,但在我看来,状态机及其图是处理并行/多线程工作流的终极工具。
实际上,您在图中建模的每个状态机都代表了并行性及其事件、交互点。
请查看我的图表 href="https://mehmetsalgar.wordpress.com/2022/04/18/a-model-driven-event-sourced-cloud-ready-application-with-akka-finite-state-machine-using-kafka-cassandra -and-elasticsearch/" rel="nofollow noreferrer">博客。正如您所看到的信用状态机、信用评分状态机、地址检查状态机和欺诈预防状态机,它们在 Apache Kafka 的帮助下并行工作用于业务案例。
I would tell you something more radical, yes I agree Activity Diagrams are really useful to represent parallel flow but in my opinion State Machines and their diagrams are the ultimate tool to deal with parallel/multi-threaded workflows.
Practically every State Machine you model in Diagrams represents the prallelity and their Events, theirs interaction points.
Please look into this diagram from my Blog. AS you can see Credit State Machine, Credit Score State Machine, Address Check State Machine and Fraud Prevention State Machine, they all work in parallel for Business Case with the help of Apache Kafka.