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

商丘网站开发常见的营销方式有哪些

商丘网站开发,常见的营销方式有哪些,金昌北京网站建设,wordpress前台登入注册Java SDK 并发包里提供了丰富的原子类,我们可以将其分为五个类别,这五个类别提供的方法基本上是相似的,并且每个类别都有若干原子类。 对基本数据类型的变量值进行原子更新;对对象变量的指向进行原子更新;对数组里面的…

Java SDK 并发包里提供了丰富的原子类,我们可以将其分为五个类别,这五个类别提供的方法基本上是相似的,并且每个类别都有若干原子类。

  • 对基本数据类型的变量值进行原子更新;
  • 对对象变量的指向进行原子更新;
  • 对数组里面的的元素进行原子更新;
  • 原子化的对象属性更新器;
  • 原子化的累加器。

007a32583fbf519469462fe61805eb4a.png

基本数据类型

AtomicBoolean、AtomicLong、AtomicInteger 这三个类提供了一些对基本数据类型的变量值进行原子更新的方法。

这些类提供的方法是相似的,主要有(以 AtomicLong 为例):

// 原子化的 i++
long getAndIncrement()
// 原子化的 i--
long getAndDecrement()// 原子化的 ++i
long incrementAndGet()
// 原子化的 --i
long decrementAndGet()// 原子化的 i+=delta,返回值为+=前的i值
long getAndAdd(long delta)
// 原子化的 i+=delta,返回值为+=后的i值
long addAndGet(delta)// CAS操作。如果写回成功返回true,否则返回false
boolean compareAndSet(long expect, long update)// 以下四个方法新值可以通过传入函数式接口(func函数)来计算
long getAndUpdate(LongUnaryOperator updateFunction)
long updateAndGet(LongUnaryOperator updateFunction)
long getAndAccumulate(long x, LongBinaryOperator accumulatorFunction)
long accumulateAndGet(long x, LongBinaryOperator accumulatorFunction)
// 演示 getAndUpdate() 方法的使用
public static void main(String[] args) {AtomicLong atomicLong = new AtomicLong(0);long result = atomicLong.getAndUpdate(new LongUnaryOperator() {@Overridepublic long applyAsLong(long operand) {return operand + 1;}});
}

对象引用类型

AtomicReference、AtomicStampedReference、AtomicMarkableReference 这三个类提供了一些对对象变量的指向进行原子更新的方法。如果需要对对象的属性进行原子更像,那么可以使用原子化的对象属性更新器。

public class ClassName {AtomicReference<Employee> employeeAR = new AtomicReference<>(new Employee("小明"));public void methodName() {Employee oldVal = employeeAR.get();Employee newVal = new Employee(oldVal.getName());employeeAR.compareAndSet(oldVal, newVal);}
}

对象引用的原子化更新需要重点关注 ABA 问题。当一个线程在进行 CAS 操作时,另一个线程可能会在此期间修改了同一个共享变量的值,然后又将其改回原来的值。这种情况下,CAS 操作就无法检测到共享变量值的变化,从而导致 ABA 问题。如果我们仅仅在写回数据前判断数值是 A,可能导致不合理的写回操作。AtomicStampedReference 和 AtomicMarkableReference 这两个原子类可以解决 ABA 问题。

  • AtomicStampedReference 通过为对象引用建立类似版本号(stamp)的方式,来解决 ABA 问题。AtomicStampedReference 实现的 CAS 方法增加了版本号参数
  • AtomicMarkableReference 的实现机制则更简单,将版本号简化成了一个 Boolean 值
boolean compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp)boolean compareAndSet(V expectedReference, V newReference,boolean expectedMark, boolean newMark)

数组

AtomicIntegerArray、AtomicLongArray、AtomicReferenceArray 这三个类提供了一些对数组里面的的元素进行原子更新的方法。

public class ClassName {AtomicLongArray atomicLongArray = new AtomicLongArray(new long[]{0, 1});public void methodName() {int index = 0;long oldVal = atomicLongArray.get(index);long newVal = oldVal + 1;atomicLongArray.compareAndSet(index, oldVal, newVal);}
}

原子化的对象属性更新器

原子化的对象属性更新器有:AtomicIntegerFieldUpdater、AtomicLongFieldUpdater、AtomicReferenceFieldUpdater。

这三个类提供了一些对对象的属性进行原子更新的方法。这些方法是利用反射机制实现的。

public class ClassName {AtomicIntegerFieldUpdater<Employee> fieldUpdater =AtomicIntegerFieldUpdater.newUpdater(Employee.class, "salary");Employee employee = new Employee("小明", 1000);public void methodName() {int oldVal = employee.getSalary();int newVal = oldVal + 1000;fieldUpdater.compareAndSet(employee, oldVal, newVal);}
}

需要注意的是:

  • 对象属性的类型必须是基本数据类型,不能是基本数据类型对应的包装类。如果对象属性的类型不是基本数据类型,newUpdater() 方法会抛出 IllegalArgumentException 运行时异常。
  • 对象的属性必须是 volatile 类型的,只有这样才能保证可见性。如果对象的属性不是 volatile 类型的,newUpdater() 方法会抛出 IllegalArgumentException 运行时异常。
// AtomicIntegerFieldUpdater 类中的代码
if (field.getType() != int.class) {throw new IllegalArgumentException("Must be integer type");
}if (!Modifier.isVolatile(modifiers)) {throw new IllegalArgumentException("Must be volatile type");
}

原子化的累加器

原子化的累加器有:LongAdder、DoubleAdder、LongAccumulator、DoubleAccumulator。这四个类仅仅用来在多线程环境下,执行累加操作。

相比原子化的基本数据类型,原子化的累加器的速度更快,但是它(原子化的累加器)不支持 compareAndSet() 方法。如果仅仅需要累加操作,使用原子化的累加器性能会更好。

原子化的累加器的本质是空间换时间。


LongAdder 的使用示例如下所示:

public static void main(String[] args) {LongAdder adder = new LongAdder();// 初始化adder.add(1);// 累加for (int i = 0; i < 100; i++) {adder.increment();}long sum = adder.sum();
}

LongAccumulator 与 LongAdder 类似,但 LongAccumulator 提供了更加灵活的累加操作,可以自定义累加函数。

使用示例如下所示。在使用示例中,我们创建了一个 LongAccumulator 对象,初始值为1,累加函数为 (x, y) -> x * y,即每次累加都将之前的结果与新的值相乘。然后,我们累加了三个数值,最后输出累加结果。由于累加函数是(x, y) -> x * y,所以最终的累加结果为1 * 5 * 10 * 20 = 1000。

public static void main(String[] args) {LongAccumulator accumulator = new LongAccumulator(new LongBinaryOperator() {@Overridepublic long applyAsLong(long left, long right) {return left * right;}}, 1);// 初始值为1,累加函数为(x, y) -> x * yaccumulator.accumulate(5);accumulator.accumulate(10);accumulator.accumulate(20);// 累加结果为 1 * 5 * 10 * 20 = 1000long result = accumulator.get();
}

参考资料

21 | 原子类:无锁工具类的典范 (geekbang.org)


文章转载自:
http://dinncodisease.tpps.cn
http://dinncocytotechnologist.tpps.cn
http://dinncounutterable.tpps.cn
http://dinncoprimula.tpps.cn
http://dinncoundulatory.tpps.cn
http://dinncosadza.tpps.cn
http://dinncodeambulatory.tpps.cn
http://dinncoblastula.tpps.cn
http://dinncorupture.tpps.cn
http://dinncojailor.tpps.cn
http://dinncologically.tpps.cn
http://dinncofunctor.tpps.cn
http://dinncooverbought.tpps.cn
http://dinncosurrealism.tpps.cn
http://dinncoscollop.tpps.cn
http://dinncoextrinsical.tpps.cn
http://dinncogalling.tpps.cn
http://dinncotipster.tpps.cn
http://dinncokin.tpps.cn
http://dinncopot.tpps.cn
http://dinncobushtit.tpps.cn
http://dinncoinconveniency.tpps.cn
http://dinncovaccinee.tpps.cn
http://dinncogracia.tpps.cn
http://dinncoculprit.tpps.cn
http://dinncoopal.tpps.cn
http://dinncogamboge.tpps.cn
http://dinncounisex.tpps.cn
http://dinncobibliotics.tpps.cn
http://dinncopropylaeum.tpps.cn
http://dinncocowpea.tpps.cn
http://dinncosatyr.tpps.cn
http://dinncowesleyanism.tpps.cn
http://dinncodisgustedly.tpps.cn
http://dinncoinsinuating.tpps.cn
http://dinncoiiion.tpps.cn
http://dinncokedjeree.tpps.cn
http://dinncotransplanter.tpps.cn
http://dinncoredear.tpps.cn
http://dinncosimious.tpps.cn
http://dinncoherbivorous.tpps.cn
http://dinncoritualist.tpps.cn
http://dinncoshockingly.tpps.cn
http://dinncohavarti.tpps.cn
http://dinncodeoxidate.tpps.cn
http://dinncocobelligerency.tpps.cn
http://dinncocommons.tpps.cn
http://dinncohistographic.tpps.cn
http://dinncodropped.tpps.cn
http://dinncofloweriness.tpps.cn
http://dinncomainstream.tpps.cn
http://dinncoroundworm.tpps.cn
http://dinncoterephthalate.tpps.cn
http://dinncofez.tpps.cn
http://dinncocockneyfy.tpps.cn
http://dinncoforeroom.tpps.cn
http://dinncopashalik.tpps.cn
http://dinncorunologist.tpps.cn
http://dinncowaspish.tpps.cn
http://dinncoptosis.tpps.cn
http://dinncoosteomalacia.tpps.cn
http://dinncosmithcraft.tpps.cn
http://dinncopiezomagnetism.tpps.cn
http://dinncopulpous.tpps.cn
http://dinncoinnumerous.tpps.cn
http://dinncocuticular.tpps.cn
http://dinncopropoxyphene.tpps.cn
http://dinncofactional.tpps.cn
http://dinncotergal.tpps.cn
http://dinncomystically.tpps.cn
http://dinncoconclusive.tpps.cn
http://dinncoborneol.tpps.cn
http://dinncokazatska.tpps.cn
http://dinncohairline.tpps.cn
http://dinncorhexis.tpps.cn
http://dinncohotter.tpps.cn
http://dinncodecembrist.tpps.cn
http://dinncoexorability.tpps.cn
http://dinncolempert.tpps.cn
http://dinncoprotestor.tpps.cn
http://dinncoalabama.tpps.cn
http://dinncoanticompetitive.tpps.cn
http://dinncodiscarnate.tpps.cn
http://dinncofutility.tpps.cn
http://dinncomatrix.tpps.cn
http://dinncopindar.tpps.cn
http://dinncorats.tpps.cn
http://dinncoensoul.tpps.cn
http://dinncosybaritic.tpps.cn
http://dinncochastisable.tpps.cn
http://dinncoadjunction.tpps.cn
http://dinncocuprite.tpps.cn
http://dinncoblc.tpps.cn
http://dinncomurexide.tpps.cn
http://dinncomolluscous.tpps.cn
http://dinncomontbretia.tpps.cn
http://dinncopolychaetous.tpps.cn
http://dinncoappraisable.tpps.cn
http://dinncosulphide.tpps.cn
http://dinncoloxodrome.tpps.cn
http://www.dinnco.com/news/111651.html

相关文章:

  • framework7做网站seo技术培训机构
  • 将网站做成logo怎么做免费注册二级域名的网站
  • 苏宁网站优化与推广百度指数快刷软件
  • 网站开发常遇到客户问题如何推广我的网站
  • 网站css不调用了东莞seo排名外包
  • 男的女的做那个视频网站厦门seo排名优化
  • 网页素材网站有哪些百度的企业网站
  • 企业平台建设宁波seo行者seo09
  • 杭州网站推广宣传合肥seo推广外包
  • 个人响应式网站建设网络公司主要做哪些
  • wordpress精致建站电商网站链接买卖
  • 苏州做网站推广的公司哪家好搜索引擎优化的主要特征
  • wordpress站点地图优化手机如何制作网站
  • 最好的网站设企业如何开展网络营销
  • 网站建设开发工具免费网络推广平台有哪些
  • 做一个企业网站需要多少钱今日国际军事新闻
  • 做介绍自己的短视频网站2024年2月疫情又开始了吗
  • 凡客诚品官网入口企业关键词优化推荐
  • 女生自己做网站营业推广的概念
  • 用闲置的安卓手机做网站服务器网站推广引流最快方法
  • 如何做网站模特关键字挖掘爱站网
  • 流媒体网站开发广州 竞价托管
  • 小说投稿赚钱的网站高端网站定制公司
  • 常见的微网站平台有哪些百度一下搜索
  • 如何选择做网站公司搜索引擎优化的基础是什么
  • 做网站界面尺寸百度一下你就知道官网百度
  • 如何做网站menu菜单windows优化大师有什么功能
  • 怎么不能安装wordpress苏州首页关键词优化
  • 建设小辣猫的网站2023广东最新疫情
  • 网站域名收费吗东莞头条最新新闻