简单的线程池

package vortex.practise.Threads;

import java.util.LinkedList;
import java.util.List;

public class ThreadPool {
	
	//单例返回变量
	private static ThreadPool instance = null;
	//内部类数组
	private static InnerFactory[] IF;
	//线程池大小
	private static int poolSize = 0;
	//队列
	private static LinkedList<Runnable> queue = new LinkedList<Runnable>();
	
	//私有构造器
	private ThreadPool(){
	}
	//获得单例
	public static ThreadPool getNewInstance(){
		if(instance==null){
			instance = new ThreadPool();
		}
		return instance;
	}
	//创建线程池
        //根据传入的参数开启内部类的线程
	public void createPool(int size){
		this.poolSize = size;
		IF = new InnerFactory[size];
		for(int i=0;i<size;i++){
			IF[i] = new InnerFactory();
			IF[i].start();
		}
	}
	
//传入参数放置进入队列
	public void excuteThread(Runnable[] runs) throws Exception{
		if(poolSize==0){
			throw new Exception("please create poolSize!");
		}
		if(runs==null){
			throw new Exception("no parameters!");
		}else{
			for(Runnable run:runs){
				synchronized(queue){
					queue.addLast(run);
					queue.notify();
				}
			}
		}
	}
	
	/**
	 * 
	 * @author Vortex
	 *
	 * 
	 */
	private class InnerFactory extends Thread{

		public void run() {
			// TODO Auto-generated method stub
			Runnable r;
			int flag = 0;
			while(true){
				synchronized(queue){
					
					while(queue.isEmpty()){
						try {
							queue.wait();
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					r = queue.removeFirst();
					r.run();
				}
			}
		}
		
	}
}

 

 笔记。

经纬度转换为UTM坐标 UTM(通用横向墨卡托投影): 是一种以米为单位的坐标系统,用于地图和GPS导航。将地球划分为60个纵向的区域。每个区域宽6度,从赤道开始往南北两级方向划分。每个区域都有一个特定的字母。 阅读详情

相关推荐

雷电模拟器+Python 3.11:手把手教你用Frida-dexdump给安卓APK脱壳(附GDA查壳)

本文详细介绍了如何使用雷电模拟器和Python 3.11配合Frida-dexdump工具进行安卓APK脱壳的全流程。从环境配置、工具安装到脱壳操作和问题排查,提供了包含30+关键截图的保姆级教程,适合零基础用户快速上手。重点讲解了Frida工具链的使用技巧和GDA查壳方法,帮助读者掌握移动应用安全分析的基础技能。

weixin_42568801的博客 329

JAVA创建简单的线程池

JAVA创建简单的线程池 package com.indi.zeus.controller; import com.indi.zeus.common.BaseReturn; import com.indi.zeus.common.ReturnResponse; import com.indi.zeus.common.codeenum.UErrCode; import com.indi.zeus....

K的博客 213

保姆级教程:用Jetson Orin Nano和ROS2 Humble搞定PIXhawk 4飞控通信(含配置文件详解)

本文提供了一份详细的Jetson Orin Nano与PIXhawk 4飞控通信配置指南,涵盖硬件连接、ROS2 Humble环境搭建、MAVROS2配置及通信调试全流程。通过实战案例和配置文件详解,帮助开发者快速实现无人机上位机与飞控的稳定通信,适用于无人机开发与自动化控制场景。

weixin_33670786的博客 475

自己动手实现简单的线程池

为了节省系统在多线程并发情况下不断的创建新和销毁线程所带来的性能浪费,就需要引入线程池。 线程池的基本功能就是线程复用。每当系统提交一个任务时,会尝试从线程池内取出空闲线程来执行它。如果没有空闲线程,这时候再创建新的线程。任务执行完毕,线程也不会立即销毁,而是加入到线程池中以便下次复用。

张小琦的博客专栏 3308

从数据校准到论文呈现:fsQCA与NCA方法融合的完整实证研究指南

本文详细介绍了fsQCA(模糊集定性比较分析)与NCA(必要条件分析)方法融合的完整实证研究流程,从数据校准到论文呈现。通过软件操作技巧、R语言NCA包高效使用及论文写作规范,帮助研究者避免常见误区,提升研究质量与可靠性。特别适合需要进行组态分析的研究生和学者参考。

weixin_29215391的博客 420

混合动作空间在强化学习中的创新应用:PDQN与MPDQN算法解析

本文深入解析了强化学习中处理混合动作空间的PDQN与MPDQN算法。针对既有离散选择又有连续调节的复杂决策场景,PDQN通过参数化深度Q网络,巧妙结合DQN与DDPG进行交替优化;MPDQN则进一步改进,为每个离散动作提供专属参数评估以减少干扰。文章通过游戏、自动驾驶等实例阐述了其应用价值与面临的挑战。

efc123456的博客 865

简单线程池实现

本文基于Linux中的进程同步和互斥实现了一个简单的线程池~

2201_75479723的博客 1135

GitLab中国区注册终极解决方案:绕过+86手机验证的实战技巧(2023最新)

本文详细解析了GitLab中国区注册时绕过+86手机验证的三种实战技巧,包括开发者工具调试方案、使用国际号码的变通方案以及本地化部署替代方案。通过技术分析和实践验证,帮助开发者顺利注册GitLab账号,提升团队协作效率。

rl6adventurer的博客 1505

【Linux】简单的线程池

介绍简单线程池的模拟实现

博主在编程学习中的总结、笔记 858

基于Freertos与lwip移植FreeModbusTcp协议

基于FreeRTOS的N32G457VEL7之LWIP网络协议栈移植-优快云博客。

Dd_456456的博客 3239

【SEW-伺服电机-Profinet-io通讯控制——伺服配置】

SEW-伺服电机-Profinet-io通讯控制——伺服配置一、本次使用配置说明编写经历受国际形式与疫情影响相关资料查询阅读测试验证不易二、伺服配置流程1.基本准备条件2.硬件-电路连接3.设备在线连接4.软件-参数配置5.手动运行测试6.PN-IO自动控制配置8.PLC1200硬件组态9.PLC软件编程10.调试故障分析三、总结四、参考 一、本次使用配置说明编写经历 受国际形式与疫情影响 由于近期受国际形式影响以及全球疫情影响,Siemens等常用产品供货期与供货量严重受限,项目上不得不采取选用其它替代产

qq_39024187的博客 1万+

手写一个简单的线程池

本文介绍了如何手写一个简单的线程池,并逐步实现线程复用和多线程复用的功能。线程池的核心原理是通过减少频繁创建和销毁线程的开销来提升性能。线程池主要由一个线程集合和一个任务队列组成,任务提交时,首先判断核心线程是否已满,未满则创建核心线程执行任务,已满则加入任务队列。若队列也满,则创建非核心线程执行任务,非核心线程在空闲一段时间后会被销毁。如果线程数达到最大值,则执行拒绝策略。文章通过代码示例展示了如何实现一个简单的线程池,并逐步扩展为支持多线程复用的线程池。

bossDDYY的博客 1059

使用 MATLAB/Simulink 构建一个 核电站汽轮机与发电机协调控制系统 的仿真模型

在核电机组中,汽轮机-发电机系统是将核能最终转化为电能的关键环节。与火电机组不同,核反应堆的热惯性大、功率调节慢,因此汽轮机的控制策略需与反应堆特性相匹配,实现安全、稳定、高效的能量转换。维持发电机输出功率/频率稳定(响应电网调度)调节汽轮机进汽压力(匹配一回路蒸汽供应)实现“堆-机协调控制”保障机组在启停、变负荷、甩负荷等工况下的安全性本教程将带你使用构建一个核电站汽轮机与发电机协调控制系统汽轮机调速系统(调门控制)建模发电机与电网接口建模(同步机)

xiaoheshang_123的博客 190

深入了解Java线程池,以及如何实现一个简单的线程池

线程池是一种基于池化技术设计用于管理线程生命周期的框架或模式。它允许开发者创建一组工作线程,这些线程可以反复被用来执行不同的任务,而不是每次执行任务时都创建和销毁线程。

Ylxb_的博客 888

深度学习工具包 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")

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

线程池--简单版本和复杂版本

/模拟任务编号void *arg;//回调函数参数//任务的回调函数}PoolTask;//最大任务个数//实际任务个数,小于等于max_job_num//任务队列数组//入队位置,在这个地方添加任务// 出队位置//线程池内线程个数//线程池内线程数组//是否关闭线程池//线程池的锁//任务队列为空的条件//任务队列不为空的条件//线程池//创建线程池--thrnum 代表线程个数,maxtasknum 最大任务个数//摧毁线程池//添加任务到线程池。

莫浅子的博客 624

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

简单线程池的实现

1. 什么是线程池 线程池是线程的集合,拥有若干个线程,线程池中的线程一般用于执行大量的且相对短暂的任务。如果一个任务执行的时间很长,那么就不适合放在线程池中处理,比如说一个任务的执行时间跟进程的生命周期是一致的,那么这个线程的处理就没有必要放到线程池中调度,用一个普通线程即可。 线程池中线程的个数太少的话会降低系统的并发量,太多的话又会增加系统的开销。一般而言,线程池中线程的个数与线

chengonghao的博客 2259

简单线程池教程

在多线程的程序里面,经常要创建线程,但是创建线程的过程是十分耗费资源的,而且线程是一种可以,如果一个线程可以重复反复利用,处理完一个任务后用来处理另外一个任务,那么可以节省很多的资源。因此产生了线程池,一个用来一遍提高程序的效率的功能。

wr787806的博客 539

java简单线程池_Java实现一个简单的线程池

最近研究nio,顺便实现一个线程池。package test;import java.io.IOException;import java.text.ParseException;import java.util.LinkedList;import java.util.List;public class Main {public static void main(String[] args) th...

weixin_35070219的博客 230

线程池的简单实现

线程池的简单实现欢迎使用Markdown编辑器线程池执行流程线程池简单代码 欢迎使用Markdown编辑器 有几天没写代码,总是感觉有些心慌,随意写一篇文章,就当是自己的知识点的重新复习。 时间过得真快,眼前的困难只是暂时的,希望在职业生涯能够保持一份奋斗之心,stay young stay hungry,成长之路希望能够感知一丝丝成就感。 本篇文章介绍下线程池,尽量把代码注释写清楚。 线程池执行...

tiane5hao的博客 188

简单线程池

ThreadPool由初始化自身、初始化线程池中的线程及添加任务方法构成Task测试

王大人的博客 242

线程池的简单使用

许多时候为了提高效率,我们不得不去做一个线程池,下面是一个线程池最简单的使用例子,我们在其中使用了固定线程数的线程池。 在这个线程池中我们用了最为简单的例子,通过这个例子可以看到同时执行的线程数量。而且方便理解对于线程池的使用。

u012291108的博客 749

线程池简单实现FixedSizeThreadPool

线程池简单实现FixedSizeThreadPool

madeByOurselves的博客 595

Linux下简单线程池的实现

线程池的技术背景    在面向对象编程中,创建和销毁对象是很费时间的,因为创建一个对象要获取内存资源或者其它更多资源。在Java中更是如此,虚拟机将试图跟踪每一个对象,以便能够在对象销毁后进行垃圾回收。所以提高服务程序效率的一个手段就是尽可能减少创建和销毁对象的次数,特别是一些很耗资源的对象创建和销毁。如何利用已有对象来服务(不止一个不同的任务)就是一个需要解决的关键问题,其实这就是一些"池

NK_test的博客 5172

C++简单线程池

C++简单线程池线程安全任务的基类线程池任务处理线程 我们在很多情况下会使用多线程,而计算机负担有限,因此需要使用有限的线程来完成多任务,这就需要使用线程池。 线程安全 我们使用互斥对象 HANDLE hMutex; 任务的基类 class Task { public: virtual void run(){} }; 线程池 我们直接使用queue,因为我们为了线程安全已使用互斥对象 q...

qq_39721774的博客 246

Python线程池简单实现

用Python简单实现的线程池

同一片天空下 1490

【Linux】线程实例 | 简单线程池

今天来写一个简单版本的线程池more。

慕雪华年的博客 1240

简单了解线程池

线程池是一种很实用的方法,可以极大的提高效率。

Starc_的博客 958
上一篇: SpringMVC启动报错解决办法
下一篇: java socketio server 端 笔记
vortex331
博客等级 码龄16年 0粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值