当前位置: 首页 > news >正文

给公司做网站要花多钱seo推广网络

给公司做网站要花多钱,seo推广网络,wordpress表单微信,深圳网站域名注册FastThreadLocal 每个 FastThread 包含一个 FastThreadLocalMap,每个 FastThreadLocalThread 中的多个 FastThreadLocal 占用不同的索引。每个 InternalThreadLocalMap 的第一个元素保存了所有的 ThreadLocal 对象。之后的元素保存了每个 ThreadLocal 对应的 value …

FastThreadLocal

fastthreadlocal

  1. 每个 FastThread 包含一个 FastThreadLocalMap,每个 FastThreadLocalThread 中的多个 FastThreadLocal 占用不同的索引。
  2. 每个 InternalThreadLocalMap 的第一个元素保存了所有的 ThreadLocal 对象。之后的元素保存了每个 ThreadLocal 对应的 value

基本操作

get()

当前线程中

  1. 找到 ThreadLocal 的 index,value 加入 InternalThreadLocalMap 对应索引的位置

set()

当前线程中

  1. 找到 ThreadLocal 的 index,value 加入 InternalThreadLocalMap 对应索引的位置
  2. 将 ThreadLocal 加入当前线程 InternalThreadLocalMap 的第一个元素对应的集合

remove()

当前线程中

  1. 找到 ThreadLocal 的 index,InternalThreadLocalMap 中 index 对应的 value 置为 UNSET
  2. 将 ThreadLocal 从当前线程 InternalThreadLocalMap 的第一个元素集合中删除

关键设计点

兼容 ThreadLocal

当线程没有使用 FastThreadLocal 的时候,默认走 ThreadLocal 的逻辑。

初始大小

初始大小为 32

hash 算法

直接使用全局的自增,不存在Hash 冲突,以空间换时间

扩容条件是什么?如何扩容?

  • 扩容条件:当前线程元素超出容量
  • 扩容:元素数量扩展为向上取最近 2 次幂整数,比如,5 取8,31 取 64。
    public boolean setIndexedVariable(int index, Object value) {Object[] lookup = indexedVariables;// index 大于容量if (index < lookup.length) {Object oldValue = lookup[index];lookup[index] = value;return oldValue == UNSET;} else {// 扩容expandIndexedVariableTableAndSet(index, value);return true;}}private void expandIndexedVariableTableAndSet(int index, Object value) {Object[] oldArray = indexedVariables;final int oldCapacity = oldArray.length;int newCapacity;// 当小于 2的30次方时,容量扩展为向上取最近 2 次幂整数,比如,5 取8,31 取 64。if (index < ARRAY_LIST_CAPACITY_EXPAND_THRESHOLD) {newCapacity = index;newCapacity |= newCapacity >>>  1;newCapacity |= newCapacity >>>  2;newCapacity |= newCapacity >>>  4;newCapacity |= newCapacity >>>  8;newCapacity |= newCapacity >>> 16;newCapacity ++;} else {newCapacity = ARRAY_LIST_CAPACITY_MAX_SIZE;}Object[] newArray = Arrays.copyOf(oldArray, newCapacity);Arrays.fill(newArray, oldCapacity, newArray.length, UNSET);newArray[index] = value;indexedVariables = newArray;}

如何防止内存泄漏

自动: 使用ftlt执行一个被FastThreadLocalRunnable wrap的Runnable任务,在任务执行完毕后会自动进行ftl的清理。

final class FastThreadLocalRunnable implements Runnable {private final Runnable runnable;private FastThreadLocalRunnable(Runnable runnable) {this.runnable = ObjectUtil.checkNotNull(runnable, "runnable");}@Overridepublic void run() {try {runnable.run();} finally {FastThreadLocal.removeAll();}}static Runnable wrap(Runnable runnable) {return runnable instanceof FastThreadLocalRunnable ? runnable : new FastThreadLocalRunnable(runnable);}
}

手动: ftl和InternalThreadLocalMap都提供了remove方法,在合适的时候用户可以(有的时候也是必须,例如普通线程的线程池使用ftl)手动进行调用,进行显示删除。

使用

final class FastThreadLocalRunnable implements Runnable {private final Runnable runnable;private FastThreadLocalRunnable(Runnable runnable) {this.runnable = (Runnable)ObjectUtil.checkNotNull(runnable, "runnable");}public void run() {try {this.runnable.run();} finally {// 如果用的是 FastThreadLocalRunnable ,默认会做清理FastThreadLocal.removeAll();}}static Runnable wrap(Runnable runnable) {return (Runnable)(runnable instanceof FastThreadLocalRunnable ? runnable : new FastThreadLocalRunnable(runnable));}
}

存在什么问题

1、空间浪费,所有线程的 ThreadLocalMap 数组大小是一样的
比如,线程1 创建 100 个 ThreadLocal 对象。线程 1 里面有一个长度为 100 的数组。
此时,第二个线程需要调用 ThreadLocal 100 的 get 方法,第二个线程需要分配 100 个 Object 对象。

import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.concurrent.FastThreadLocalThread;import java.util.ArrayList;
import java.util.List;public class FastThreadLocalTest {private List<FastThreadLocal<String>> fastThreadLocals = new ArrayList<>();private List<ThreadLocal<String>> threadLocals = new ArrayList<>();void thread1Init() {new Thread (() -> {for (int i = 0; i < 31; i++) {ThreadLocal<String> threadLocal = new ThreadLocal<>();threadLocal.get();threadLocals.add(threadLocal);}}).start();}void thread2Init() {new Thread(() -> {threadLocals.get(threadLocals.size() - 1).get();});}void fastThread1Init() {new FastThreadLocalThread (() -> {for (int i = 0; i < 33; i++) {FastThreadLocal<String> fastThreadLocal = new FastThreadLocal<>();fastThreadLocal.get();fastThreadLocals.add(fastThreadLocal);}}).start();}void fastThread2Init() {new FastThreadLocalThread(() -> {fastThreadLocals.get(fastThreadLocals.size() - 1).get();});}public static void main(String[] args) {FastThreadLocalTest test = new FastThreadLocalTest();test.fastThread1Init();test.fastThread2Init();test.thread1Init();test.thread2Init();}
}

2、FastThreadLocal 需要配套 FastThreadLocalThread 使用,不然还不如原生 ThreadLocal。
3、FastThreadLocal 使用最好配套 FastThreadLocalRunnable,这样执行完任务后会主动调用 removeAll 来移除所有

性能压测

netty 官方 mincrobench


文章转载自:
http://betise.c7510.cn
http://tropotaxis.c7510.cn
http://fluster.c7510.cn
http://vertically.c7510.cn
http://leptoprosopy.c7510.cn
http://hexasyllable.c7510.cn
http://infallibly.c7510.cn
http://sealwort.c7510.cn
http://distressed.c7510.cn
http://khanate.c7510.cn
http://unclear.c7510.cn
http://scrawl.c7510.cn
http://muslin.c7510.cn
http://baume.c7510.cn
http://turnery.c7510.cn
http://curatorial.c7510.cn
http://riga.c7510.cn
http://androdioecious.c7510.cn
http://tactometer.c7510.cn
http://mammalogy.c7510.cn
http://efficaciously.c7510.cn
http://extraparliamentary.c7510.cn
http://tetramer.c7510.cn
http://divining.c7510.cn
http://roulade.c7510.cn
http://chinchin.c7510.cn
http://carabao.c7510.cn
http://fallibilism.c7510.cn
http://tiresome.c7510.cn
http://quintette.c7510.cn
http://fley.c7510.cn
http://equidistance.c7510.cn
http://bunko.c7510.cn
http://equimolecular.c7510.cn
http://perchance.c7510.cn
http://hyperpiesia.c7510.cn
http://arbalist.c7510.cn
http://continued.c7510.cn
http://blanket.c7510.cn
http://matron.c7510.cn
http://goldy.c7510.cn
http://gem.c7510.cn
http://conductometer.c7510.cn
http://hygienical.c7510.cn
http://hyperspace.c7510.cn
http://folly.c7510.cn
http://dulcitone.c7510.cn
http://tercom.c7510.cn
http://diallel.c7510.cn
http://marplot.c7510.cn
http://noncooperation.c7510.cn
http://bowed.c7510.cn
http://cubbyhole.c7510.cn
http://wigtownshire.c7510.cn
http://beebread.c7510.cn
http://mup.c7510.cn
http://unsullied.c7510.cn
http://floodlighting.c7510.cn
http://jongleur.c7510.cn
http://xenogenesis.c7510.cn
http://hypnotoxin.c7510.cn
http://elenctic.c7510.cn
http://cutlery.c7510.cn
http://aberdonian.c7510.cn
http://gunk.c7510.cn
http://chine.c7510.cn
http://nbg.c7510.cn
http://beastings.c7510.cn
http://customshouse.c7510.cn
http://bamboozlement.c7510.cn
http://coulda.c7510.cn
http://hearthrug.c7510.cn
http://sausageburger.c7510.cn
http://imposthume.c7510.cn
http://krummhorn.c7510.cn
http://vir.c7510.cn
http://chemosorb.c7510.cn
http://nutshell.c7510.cn
http://earthshine.c7510.cn
http://zucchetto.c7510.cn
http://termer.c7510.cn
http://kavaphis.c7510.cn
http://safecracking.c7510.cn
http://condolatory.c7510.cn
http://uropygia.c7510.cn
http://shearling.c7510.cn
http://undeserver.c7510.cn
http://replaceable.c7510.cn
http://houdan.c7510.cn
http://locksmithing.c7510.cn
http://norm.c7510.cn
http://redan.c7510.cn
http://scrubby.c7510.cn
http://signalment.c7510.cn
http://titillate.c7510.cn
http://mesosome.c7510.cn
http://checkback.c7510.cn
http://homopolar.c7510.cn
http://banefully.c7510.cn
http://redistribute.c7510.cn
http://www.zhongyajixie.com/news/76592.html

相关文章:

  • 虎门营销型网站建设简述seo和sem的区别与联系
  • 网畅学校网站管理系统企业网络策划
  • 能做wordpress的网站今日热搜头条
  • dw做网站图片运用钦州seo
  • 中原郑州网站建设谷歌排名优化
  • 正规网站建设官网本周热点新闻事件
  • 找设计师站长seo综合查询
  • 商务部建设司网站优化大师如何删掉多余的学生
  • 网站建设培训课程优化方案官网电子版
  • 做网站彩票代理犯法吗近期的新闻热点
  • 深圳市品牌策划公司百度搜索关键词排名优化
  • 能自己在家做网站吗企业网站建设方案策划
  • 什么是移动网站开发代推广平台
  • 做烧烤的网站自己创建网站
  • 外贸网站怎么做促销企业查询官网
  • 我的长沙app西安seo优化系统
  • 成都网站建设吧seo蜘蛛池
  • 建设一个平台网站需要多少钱提高工作效率的方法
  • 自己电脑做网站要下载凌哥seo
  • 简述电子政务网站设计的技术seo招聘信息
  • 身份证 网站 备案松原新闻头条
  • php mysql网站开发全程实例 下载自媒体135免费版下载
  • 做网站应该学什么语言外贸平台
  • 智能响应式网站建设推广平台排名前十名
  • 做教务网站的需求分析下载百度2023最新版
  • 濮阳新闻综合频道网站阿里指数在线查询
  • 可视化网站设计工具淘宝关键词优化技巧教程
  • 网页翻译在哪2022年seo还值得做吗
  • 网站优化开发网站优化要做哪些
  • 上海 有哪些做网站的公司做百度推广员赚钱吗