OkOne-如何给okhttp的请求设置优先级

小米手机安装Burp证书失败原因与DER格式改造指南 CA证书是HTTPS抓包和移动安全测试的基础组件,其本质是遵循X.509标准的数字凭证,依赖ASN.1/DER编码格式与完整证书链实现可信验证。Android系统默认支持PEM和DER两种编码,但MIUI自14版本起强化安全策略,仅识别DER二进制格式,并强制校验Subject Alternative Name(SAN)、Basic Constraints及证书链完整性。这种企业级加固逻辑导致Burp Suite导出的PEM格式.cer文件在小米设备上‘安装成功但无效’。本文聚焦证书格式转换、SAN字段注入 阅读详情

前言

当APP中有发起大量服务端接口调用请求时,或许有人希望能够指定某些请求任务的优先级较高,可以优先发起请求。或者指定其为低优先级,在靠后的位置再发起请求。那么如果可以给这些请求设置优先级,使之能够按优先级顺序执行的话就很方便了。

不过遗憾的是,OkHttp库不支持开发者给Request设置优先级。若要支持按优先级调度,则需要业务方自行维护请求任务队列,然后通过Call#execute方法依次执行请求任务,但该方案的弊端是不能利用OkHttp原有的请求队列管理,且对业务方具有侵入性。或者通过给Dispatcher设置自定义的ExecutorService,队列使用PriorityBlockingQueue,但该方式仅在执行任务且核心线程数满的情况下,任务进入PriorityBlockingQueue才能达到优先级调度的目的,且同样具有侵入性。

能否让开发者在利用OkHttp原有请求队列管理且不需要额外扩展自定义配置的基础上,只需要一行代码就可以给请求设置优先级呢?可以借助OkOne库来实现。

如何设置

首先集成OkOne库,集成步骤详见 https://github.com/chidehang/OkOne 。

集成后便可只用一行代码就能够设置请求优先级:

// 创建请求Request
Request request = Request.Builder().url(api).build();
// 给Request设置一个优先级
OkOne.setRequestPriority(request, priority);

有一点需要说明的是:Call#enqueue发起请求任务,若OkHttp内部的请求中队列(runningAsyncCalls)未达到最大并发数限制,则该任务会立即执行,否则任务会暂时在等待队列(readyAsyncCalls)中等待调度执行。因此优先级只对排队待执行的任务有意义。

效果演示

  1. 创建多个Request,并随机设置优先级
        val N = 10
        val requests = arrayOfNulls<Request>(N)
        val r = Random(System.currentTimeMillis())
        for (i in 0 until N) {
   
   
            // 随机生成请求优先级
            val priority = r.nextInt(20) - 10
            // 打印日志
            LogUtils.d(TAG, "$i => $priority")
            requests[i] = Request.Builder()
                    .url(api)
                    // TagEntity记录创建顺序和优先级,仅用于后续打印信息
                    .tag(
全景相机APP 以下是一款**全景相机APP**的完整源码,支持全景照片拍摄(多帧拼接)、全景预览、鱼眼矫正、图片保存/分享、360°全景查看等核心功能,基于Android原生Camera2 API(替代过时的Camera API) + OpenCV(图像拼接) + GLSurfaceView(全景预览)实现,适配Android 8.0+设备,可直接编译运行。runOnUiThread(() -> tvFrameCount.setText("已拍摄:" + frameCount + "帧"));// X轴旋转(上下) 阅读详情

相关推荐

机电类毕业设计资源库:20万题目解析与高效选题实战指南

毕业设计是工科学生综合运用专业知识解决实际工程问题的重要环节,其核心在于选题与方案设计。一个优秀的选题需兼顾理论深度与实践可行性,并能有效连接基础知识与前沿技术。在机电工程、自动化等领域,毕业设计通常涉及机械设计、控制系统、嵌入式开发及软件工程等多个技术模块,其价值在于通过项目实践,系统化地锻炼学生的工程设计、算法实现与系统集成能力。本文聚焦于如何高效利用一个汇集了近20万份机电类毕业设计题目的资源库,通过解析其分类体系与题目构成,并结合**单片机**、**PLC**等核心控制平台的应用场景,为读者提供从选

weixin_30443731的博客 479

​基于stm32的智能空气加湿器设计(含源代码和Proteus仿真)

课程设计分享

LoongSTUDIO的博客 2948

win10下面安装MTK USB VCOM 驱动

win10下面安装MTK USB VCOM 驱动1.概述2.驱动准备3.主要步骤3.1禁用win10对没有签名驱动限制3.2通过设备管理器安装mtk usb vcom驱动3.3工具版本问题4.禁用win10对没有签名的驱动限制4.1在设置中打开 更新和安全4.2进入恢复4.3在高级启动中点击立即重新启动4.4电脑重启后的几个动作5.通过设备管理器安装MTK USB VCOM 驱动5.1准备驱动5....

qimi123456的专栏 3万+

从KVM虚拟化到Openstack云化架构综述

目录 摘要 OpenStack的虚拟化技术 OpenStack架构介绍 Nova Swift KeyStone Neutron Glance Cinder Ceilometer Heat 摘要 这两年的工作中,接触到公有云和私有云的项目还不少。起初对于Openstack的了解,仅停留在其几大组件的交互上,如Nova、Neutron、Glance等,以及对各大云厂商功能点上...

liyunpeng229的博客 2059

保姆级教程:用MATLAB搞定双目相机标定,从导入图片到参数解读全流程

本文提供了一份详细的MATLAB双目相机标定全流程指南,涵盖从图片准备到参数解读的每个环节。重点讲解了棋盘格选择、拍摄技巧、MATLAB工具箱设置及参数优化,帮助读者避免常见错误并提升标定精度。特别适合机器人导航、三维重建等领域的开发者。

weixin_33737134的博客 436

【Proteus】51单片机交通灯信号模拟仿真示例一

【Proteus】51单片机交通灯信号模拟仿真示例

perseverance51博客 2139

RT-DETR改进策略【卷积层】| CGblock 内容引导网络 利用不同层次信息,提高多类别分类能力 (含二次创新)

本文记录的是利用中的模块优化的目标检测网络模型。通过局部特征提取器、周围环境提取器、联合特征提取器和全局环境提取器来提取局部特征、周围环境和全局环境信息,充分利用不同层次的信息。本文将其应用到中,并进行二次创新,使网络能够更好的处理多类别目标的分类能力。CGNet: A Light-Weight Context Guided Network for Semantic Segmentation1️⃣ 首先通过局部特征提取器floc(∗)floc(*)floc(∗)和周围环境提取器fsur(∗)f_{sur }

Limiiiing的博客 1367

需求跟踪详解

需求跟踪是指在软件项目开发过程中,建立并维护需求与项目各阶段工作产物(如设计文档、代码模块、测试用例等)之间对应关系的过程。它不仅记录需求从提出到实现的完整路径,还能反映需求变更时对各阶段工作的影响范围,是连接用户期望与实际软件开发产出的桥梁。

跟佟格湾一起学习计算机知识吧~ 1428

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

上一篇: OkOne-高级功能之OkHttp预建连以及原理剖析
下一篇: 从零手写实现简易版MMKV(一)
分则能成
博客等级 码龄15年 47粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值