avatar
java的volatile# Java - 爪哇娇娃
s*1
1
最早在这个版看到有MM讲etsy的时候才1M出头,这么快就翻了一番,啊..
avatar
Y*G
2
对于volatile成员,java只是标注一下
比如
public class App {
volatile int a = 1;
...
}
用javap看byte code,
...
volatile int a;
flags: ACC_VOLATILE
我以前猜java会对于volatile产生优化的代码,比如
public class App {
volatile int a = 1;
public static void main(String[] args) {
App app = new App();
int x = app.a;
System.out.printf("%d%n", x);
x = app.a;
System.out.printf("%d%n", x);
}
}
但是实际上,在第二次 "x = app.a"的时候,java产生同第一次"x = app.a"相同的代
码。这是,俺猜恍然大悟,优化是在运行的时候做的,而不是在编译的时候做的。
另外,赋值操作已经是原子操作了。如果你增加setA和getA函数,完全没有必要加
synchronize关键字。但是你如果要实现其他操作,比如addA(int delta),那你就需要
synchronize关键字了。
avatar
h*e
3
哦,大家有在etsy上有店的吗? :)
avatar
l*n
4
我的理解,getA()和setA()应该不是原子操作,这个在thinking in java 上面特意拿
出来一个例子强调了一下,会出问题的。我明天去另一个电脑找一下然后贴上来。
avatar
p*y
5
etsy要卖的出去我觉得是要有特色,要是没特色那就碰运气
avatar
w*z
6
long 的read 不是atomic, int是。

【在 l******n 的大作中提到】
: 我的理解,getA()和setA()应该不是原子操作,这个在thinking in java 上面特意拿
: 出来一个例子强调了一下,会出问题的。我明天去另一个电脑找一下然后贴上来。

avatar
s*1
7

从去年年中开始很大一片市场被韩国配件的耳环项链占据了,好多一样的“handmade”
的东西,还都卖得很好...

【在 p***y 的大作中提到】
: etsy要卖的出去我觉得是要有特色,要是没特色那就碰运气
avatar
Y*G
8
are you sure?
http://fuseyism.com/classpath/doc/java/util/concurrent/atomic/A
JDK code does not use synchronize keywork in set method:
77: /**
78: * Sets to the given value.
79: *
80: * @param newValue the new value
81: */
82: public final void set(long newValue) {
83: value = newValue;
84: }
85:

【在 w**z 的大作中提到】
: long 的read 不是atomic, int是。
avatar
p*y
9
其实卖韩式怎么说呢,还是满讨巧的,做起来巨容易,基本没有手工技巧,而且买的人
还不少
话说我换版的韩饰怎么没人要,跟风进了点零件,我自己其实不是韩饰控,这下好了,
都屯在家里了
avatar
Y*G
10
这里似乎是正解
http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jl
... a single write to a non-volatile long or double value is treated as two
separate writes: one to each 32-bit half. This can result in a situation
where a thread sees the first 32 bits of a 64-bit value from one write, and
the second 32 bits from another write.
>>> Writes and reads of volatile long and double values are always atomic. <
<<
所以,对于volatile成员的读写一定是原子操作。
非volatile成员,除了long和double,也是原子操作

【在 Y**G 的大作中提到】
: are you sure?
: http://fuseyism.com/classpath/doc/java/util/concurrent/atomic/A
: JDK code does not use synchronize keywork in set method:
: 77: /**
: 78: * Sets to the given value.
: 79: *
: 80: * @param newValue the new value
: 81: */
: 82: public final void set(long newValue) {
: 83: value = newValue;

avatar
s*1
11

etsy上的顾客大多是老美,没见过,稀罕
mitbbs上的都是老中,知道韩饰咋回事

【在 p***y 的大作中提到】
: 其实卖韩式怎么说呢,还是满讨巧的,做起来巨容易,基本没有手工技巧,而且买的人
: 还不少
: 话说我换版的韩饰怎么没人要,跟风进了点零件,我自己其实不是韩饰控,这下好了,
: 都屯在家里了

avatar
w*z
12
As you quoted in the 5楼, "value" is defined as volatile, that makes
it atomic.
As goodbug pointed out in the earlier post, it's probably easier just to use
AtomicXXX if possible rather than messing up with volatile.

【在 Y**G 的大作中提到】
: are you sure?
: http://fuseyism.com/classpath/doc/java/util/concurrent/atomic/A
: JDK code does not use synchronize keywork in set method:
: 77: /**
: 78: * Sets to the given value.
: 79: *
: 80: * @param newValue the new value
: 81: */
: 82: public final void set(long newValue) {
: 83: value = newValue;

avatar
p*y
13
那我都弄etsy卖去
avatar
l*n
14
Here I post the an example from thinking in java:
If you blindly apply the idea of atomicity, you see that getValue( ) in the
following program fits the description:
//: concurrency/AtomicityTest.java
import java.util.concurrent.*;
public class AtomicityTest implements Runnable {
private int i = 0;
public int getValue() { return i; }
private synchronized void evenIncrement() { i++; i++; }
public void run() {
while(true)
evenIncrement();
}
public static void main(String[] args) {
ExecutorService exec = Executors.newCachedThreadPool();
AtomicityTest at = new AtomicityTest();
exec.execute(at);
while(true) {
int val = at.getValue();
if(val % 2 != 0) {
System.out.println(val);
System.exit(0);
}
}
}
} /* Output: (Sample)
191583767
*///:~
However, the program will find non-even values and terminate. Although
return i is indeed an atomic operation, the lack of synchronization allows
the value to be read while the object is in an unstable intermediate state.
On top of this, since i is also not volatile, there will be visibility
problems. Both getValue( ) and evenIncrement( ) must be synchronized. Only
concurrency experts are qualified to attempt optimizations in situations
like this; again, you should apply Brian’s Rule of Synchronization.
Anyone has some idea of this? the i is int here and evenIncreasement method
is synchronized here. It explains that getValue() is not Atomic process.
avatar
s*1
15

江湖上又将掀起一阵血雨腥风了... lol

【在 p***y 的大作中提到】
: 那我都弄etsy卖去
avatar
w*z
16
you can getValue after the first i++ since getValue is not synchronized.
besides, i is not volatile, the caller thread might never see the new value.
it might read i from processor cache.

the

【在 l******n 的大作中提到】
: Here I post the an example from thinking in java:
: If you blindly apply the idea of atomicity, you see that getValue( ) in the
: following program fits the description:
: //: concurrency/AtomicityTest.java
: import java.util.concurrent.*;
: public class AtomicityTest implements Runnable {
: private int i = 0;
: public int getValue() { return i; }
: private synchronized void evenIncrement() { i++; i++; }
: public void run() {

avatar
p*y
17
LOL,我要是掀的气血雨腥风我就不愁在换版也卖不出去了

【在 s*******1 的大作中提到】
:
: 江湖上又将掀起一阵血雨腥风了... lol

avatar
l*n
18
I see. Thanks.

value.

【在 w**z 的大作中提到】
: you can getValue after the first i++ since getValue is not synchronized.
: besides, i is not volatile, the caller thread might never see the new value.
: it might read i from processor cache.
:
: the

avatar
z*a
19

MM 要是真想卖,怎么不试试ebay amazon?我看上面好像也很多卖手工jewelry的。换版
我估计是大
家新鲜劲过了,买的热情就不大了。呵呵 我猜的。

【在 p***y 的大作中提到】
: LOL,我要是掀的气血雨腥风我就不愁在换版也卖不出去了
avatar
p*y
20
你猜的没错,哈哈
ebay,amazon我没心思弄啊,list还要交费,卖了也要交费。。。

【在 z***a 的大作中提到】
:
: MM 要是真想卖,怎么不试试ebay amazon?我看上面好像也很多卖手工jewelry的。换版
: 我估计是大
: 家新鲜劲过了,买的热情就不大了。呵呵 我猜的。

avatar
s*1
21

据说etsy list和卖掉也都要交费

【在 p***y 的大作中提到】
: 你猜的没错,哈哈
: ebay,amazon我没心思弄啊,list还要交费,卖了也要交费。。。

avatar
p*y
22
要啊,所以我在换版卖么

【在 s*******1 的大作中提到】
:
: 据说etsy list和卖掉也都要交费

avatar
z*a
23

如果在ebay上,
其实MM可以稍微提高一下价格,起码把ebay的fee加进来。
我是觉得ebay毕竟用户更多,上华人的特备是换班的,相对比例少一些~
just my 2 cents, 'cause MM is such a nice person! Really wish you could
figure out ways to sell!

【在 p***y 的大作中提到】
: 要啊,所以我在换版卖么
avatar
s*1
24
现在降到1.99M了.. 购买力有这么强大?@[email protected]
avatar
p*y
25
如果要在其他地方出手的话,是要加手工费的,所以价格肯定比换版要高,换版就想换
回个材料费好给我继续败
对了,zinga mm,上次你给我建议说把那个绕的briolette下面的小红珠子做长,我照
你说的做了个,是比我原来那个设计好看,谢谢啊

【在 z***a 的大作中提到】
:
: 如果在ebay上,
: 其实MM可以稍微提高一下价格,起码把ebay的fee加进来。
: 我是觉得ebay毕竟用户更多,上华人的特备是换班的,相对比例少一些~
: just my 2 cents, 'cause MM is such a nice person! Really wish you could
: figure out ways to sell!

avatar
p*y
26
你从哪里看到这些数据的啊
我也要看
其实降到1.99M, 是说不定有一大批linsting 刚好end了,但是没几个人list新的,哈
哈,不一定是卖掉了

【在 s*******1 的大作中提到】
: 现在降到1.99M了.. 购买力有这么强大?@[email protected]
avatar
z*a
27

呵呵 不谢不谢~ 你给了我好多建议和方法呢~ 还那么详细~

【在 p***y 的大作中提到】
: 如果要在其他地方出手的话,是要加手工费的,所以价格肯定比换版要高,换版就想换
: 回个材料费好给我继续败
: 对了,zinga mm,上次你给我建议说把那个绕的briolette下面的小红珠子做长,我照
: 你说的做了个,是比我原来那个设计好看,谢谢啊

avatar
s*1
28

有道理。可能到了2M突然好多人幻灭了就不更新了..
就在etsy点了jewelry之后那页的上面啊,黑粗体的,你可能没注意

【在 p***y 的大作中提到】
: 你从哪里看到这些数据的啊
: 我也要看
: 其实降到1.99M, 是说不定有一大批linsting 刚好end了,但是没几个人list新的,哈
: 哈,不一定是卖掉了

avatar
v*3
29
我在ETSY上也有店……但是都卖不出去…………真想哭…………TOT
全都是纯手工的捏…………
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。