当前位置:网站首页>作为测试,如何理解线程同步异步
作为测试,如何理解线程同步异步
2022-07-25 20:49:00 【软件测试呀】
背景
日常测试中,程序加载数据文件,时常出现页面卡顿、程序无响应、程序崩溃等情况,排查发现与程序进程中线程的同步异步有关。
案例描述
问题描述:
使用文件查看器打开压缩文件时,出现程序无响应问题。
问题原因:
1、经排查发现,在文件查看器打开压缩文件时,会对压缩文件中所有资源进行遍历,在遍历过程中某个资源解析出错,导致任务阻塞。
2、进一步了解后发现,开发在实现功能时,将资源遍历线程放在了主线程中进行同步加载,所以资源遍历线程阻塞时,导致主线程无响应。
解决方案:
1、对资源遍历线程阻塞场景添加保护,保证遍历线程正常执行;
2、将资源遍历压缩文件线程从主线程放到子线程进行,形成异步加载,避免单个线程失败导致主线程直接挂掉,影响程序使用;
通过以上案例可以看出,逻辑实现中使用同步或异步线程,对程序的效率提升以及主线程的保护是非常重要的。
延伸思考
1、 开发层面对线程的使用:
- 使用线程的场景:
① 移动APP程序模块需要加载框架+内容时,使用线程更为高效;
② 优化程序性能时,更偏向使用线程; - 线程同步异步在程序中的应用:
① 主线程在执行任务时,将异步任务在子线程中执行,主线程无需等待子线程的结果返回,完成主线程上的操作即可,等待子线程的结果返回后,再回调给到主线程,完成整个进程。这是线程的异步加载操作,这样可以提高执行的效率(如下图);
② 主线程在执行任务1时,需等待任务1响应完成后,才能开始任务2,如任务1阻塞,则整个进程不能进行,这样的同步线程对执行效率有很大的影响(如下图)。
2、线程对测试的影响:
1)线程对case设计的影响:
① 数据流加载类的功能。这类功能多为异步线程,可以从网络层面和加载量级层面考虑测试case的设计;
② JS注入类的功能。这类功能多为同步线程,可以从注入JS功能的生效性和JS注入时机考虑测试case的设计。
2)线程对程序性能的影响:
① 从安全和性能层面考虑,同步线程虽然解决了线程的安全问题,但每次都有判断锁,导致性能降低;
② 相对同步线程来说,异步线程对程序性能的影响是积极的,效率更高,一般APP程序中都建议使用异步线程,保证程序的效率。
注意:在安全与性能之间,首先考虑的是安全,其次是性能。
结束语
了解程序实现逻辑是测试工作中必不可少的,只有了解的更细更清楚,才能对测试方案有更全面的思考,从而保证产品质量。在此希望小伙伴们技术越来越棒,在软件测试这条路上越走越高!
房子要一层一层盖,知识要一点一点学。大家在学习过程中要好基础,多上手实操,话不多说,这里狠狠上一次干货!我熬夜整理好的各阶段(功能、接口、自动化、性能、测开)技能学习资料+实操讲解,非常适合私下里学习,比找资料自学高效多了,分享给你们。
领取关 w/x/g/z/h:软件测试小dao
敲字不易,如果此文章对你有帮助的话,点个赞收个藏来个关注,给作者一个鼓励。也方便你下次能够快速查找。
边栏推荐
- Chapter VI modified specification (SPEC) class
- MPI learning notes (II): two implementation methods of matrix multiplication
- Docker builds redis cluster
- Niuke-top101-bm37
- Explain the principle of MySQL master-slave replication in detail
- [technical dry goods] how to ensure the idempotency of the interface?
- seven point two three
- The international summit osdi included Taobao system papers for the first time, and end cloud collaborative intelligence was recommended by the keynote speech of the conference
- Recommended books | essentials of industrial digital transformation: methods and Practice
- Question and answer 47: geeks have an appointment - the current monitoring system construction of CSC
猜你喜欢

leetcode-6130:设计数字容器系统
![Vulnhub | dc: 5 | [actual combat]](/img/c6/34117bbfb83ebdf9e619f4e4590661.png)
Vulnhub | dc: 5 | [actual combat]

Leetcode-155: minimum stack

Docker builds redis cluster

Learn FPGA from the bottom structure (16) -- customization and testing of pll/mmcm IP

Key network protocols in tcp/ip four layer model

增加 swap 空间

Kubernetes advanced part learning notes

Canvas 填充渐变

Remote—基本原理介绍
随机推荐
[MCU] 51 MCU burning those things
process.env
Kubernetes advanced part learning notes
牛客-TOP101-BM38
The database empties the table data and makes the primary key start from 1
Product principles of non-financial decentralized application
leetcode-6125:相等行列对
Remote monitoring solution of intelligent electronic boundary stake Nature Reserve
Unity vs -- the default debugging in VS is to start rather than attach to unity debugging
Character function and string function (2)
Principle analysis of bootloader
Basic knowledge of Marine Geology
Niuke-top101-bm38
Too many passwords, don't know how to record? Why don't you write a password box applet yourself
Remote - basic principle introduction
Oracle views the SQL statements with the slowest execution and the most queries
Follow up of Arlo's thinking
Kubernetes进阶部分学习笔记
Remote - actual combat
Leetcode-6127: number of high-quality pairs