hey everybody rob Bauer here and today

we are talking about what might be the

next big thing for Tesla in China we’ve

also got some interesting news on Tesla

and how they utilize navigation and

mapping data possibly some major battery

news a report on Tesla solar roof and

more not too much going on with the

stock again today Tesla tracking with

the NASDAQ both up about seven tenths of

a percent Tesla closing at 195.28

quickly looking ahead to tomorrow we

will get the personal consumption

expenditures report or pce report in the

morning that’ll be before Market open

but reminder that is for February so the

date at this point a little bit old this

would be before everything happened with

the banks but still will be watched

closely and then of course tomorrow is

the last day of the quarter so I’ll go

through my delivery and production

expectations and then we’ll head into

the weekend most likely expecting that

report late in the morning on Sunday

all right let’s get right into some

possibly very exciting news for Tesla in

China I think Tesla Chan on Twitter

spotting this first on LinkedIn Tesla

has posted a job opening for an

engineering program manager for energy

storage in Shanghai the description says

that Tesla’s Energy Engineering Group is

looking for a highly motivated

individual to program manage new design

engineering projects for the mega pack

program so of course we know about the

mega Factory and Lathrop scaling up to

40 gigawatt hours per year of energy

storage products it looks like Tesla may

have similar maybe even more ambitious

plans for the production of energy

storage products in China there have

been rumors for a while now about Tesla

maybe making a mega Factory there and

although this wouldn’t quite be

confirmation of that it definitely would

be the strongest tent that we have had

so far thinking about a possible Mega

Factory in Shanghai and then putting

that together with a couple of pieces of

Tesla history that we have which would

be one the ramp up that we have seen on

the mega Factory in Lathrop happening

quite quickly and then two the history

of Giga Shanghai and how quickly that

ramp happened for automotive those

things things make it extremely exciting

to think about how quickly Tesla could

possibly ramp up energy storage

production in China we’ve already seen

really great growth for Tesla energy 65

compound annual growth rate since 2016.

this is starting to form a really nice

beginning of an s-curve but as Tesla

said at an investor day just the

beginning that growth hardly looks like

anything at all compared to where Tesla

is planning on going and planning on

going pretty quickly and as we have

talked about the beautiful thing here

with Tesla energy is that so much of the

operational costs for this business are

covered by Tesla’s auto business

obviously there are going to be some

incremental operating expenses but a lot

of that girl’s profit then from Tesla

energy doesn’t even need to be that good

of gross margin a lot of that can flow

down to the bottom line so hopefully

with this job posting we’re not too far

off from hearing more about Tesla’s

official plans for their next Mega

Factory or maybe their next couple

there’s also a rumor going around Chris

John on Twitter posting about this last

night and I’ve seen this in a couple of

places probably not related but a rumor

that Elon will be visiting China next

weekend so we’ll keep an eye on that see

if anything comes of that

all right next up we’ve got a pretty big

report from Bloomberg they are reporting

on Tesla and catl being in discussions

about building a possible battery

Factory in the United States together

Bloomberg says that in recent days Tesla

has been having discussions with the

White House about this possibility and

seeking Clarity on the implications from

the inflation reduction act on a project

like this whether that’s EV credits or

battery production credits Bloomberg

says that Tesla is hoping to pursue a

similar setup to what we had talked

about between Ford and catl back in

February that was where Ford was going

to invest three and a half billion

dollars to build a lithium iron

phosphate battery Factory in Michigan

leveraging catl for their knowledge and

Technology while the factory would still

be wholly owned by Ford so that is

slated for initial production in 2026

with a plan capacity of about 35

gigawatt hours per year so from

Bloomberg’s reporting Tesla would be

pursuing a similar setup where it would

be wholly owned by Tesla licensing

technology from catl presumably for

lithium iron phosphate or some of the

newer similar technology that catl’s

been working on and although location is

not finalized it sounds like they are

considering Texas so that’s about all we

know at this point in time but obviously

Tesla could be using these batteries for

energy storage stuff that we had just

talked about certainly Vehicles as well

and Tesla has been clear that although

they are working on their own battery

production with 4680s they want to

continue to leverage battery supply from

these suppliers sounds like this would

be a little bit of a hybrid of both not

too dissimilar from the setup with

Panasonic at Giga Nevada

hopefully Tesla gets some of the clarity

that they’re looking for from the White

House and can quickly move forward on

this we’re still waiting on those

guidelines that are supposed to happen

before the end of March which we are

quickly approaching all right next up

we’ve got some pretty interesting

information from Greenlee only on

Twitter today about how Tesla is using

some of their Fleet and data collection

capabilities to improve things like

navigation and mapping so green was

taking a look at how Tesla handles

alternative routing in the navigation

system and it’s not quite as simple as

Tesla just grabbing a suggestion from

Google Maps they might take Google Maps

information and then they layer on Tesla

Maps information to make some of those

decisions but that’s not all they’re

doing the Tesla vehicles are also asking

the Tesla Maps database according to

Green for things like what parking lot

outlines are at certain locations what

else needs to be known for the route

that the Tesla is going to navigate

which can include things like stop sign

locations crosswalk information lane

information things that Tesla can

probably get some of from Google Maps

but when Tesla’s got this massive Fleet

that is driving around constantly they

should be able to build a much better

database and it does seem like that is

something that Tesla is doing which I’m

thrilled to see I’ve always kind of

wondered why Tesla hasn’t been doing

this but it looks like they have you

don’t want to become reliant on maps but

they can definitely give you information

that makes solving this incredibly

challenging problem a little bit easier

and probably a little bit safer as well

I think Tesla historically has kind of

confused people talking negatively

towards HD Maps it’s not exactly what

we’re talking about here this would be

more of kind of metadata but I think

over time as this gets more and more

robust probably approaches more into

that type of territory and as we had

already talked about with Hardware 4

seemingly including a much more precise

and robust GPS system this type of stuff

should only get better over time one of

the really cool things about this is

that green says this seems to be

updating in nearly real time one of the

elements there is speed so very much a

Waze like system where Tesla can get

really great traffic flow information

from the fleet which obviously improves

naturally as the fleet grows so some

pretty cool stuff here green shared a

couple of photos of that code showing

that it is coming from Tesla Telemetry

data and right now Tesla probably just

kind of scratching the surface of the

types of things that this can eventually

lead to

all right next up we’ve got a report on

the Tesla solar roof from CNBC today

they are citing research from wood

McKenzie that says that Tesla has only

installed 3 000 solar Roof Systems in

the US since launching the technology

where would McKenzie got this

information from and why they and CNBC

are so confident that it’s correct I’m

not sure but Tesla solar on Twitter

today replying to the article and saying

that this is incorrect by a large margin

unfortunately that was about 12 hours

after the Articles published so this is

already spread a long ways but hopefully

that interjection from Tesla implies a

little bit higher of a number for solar

roof installations historically of

course this article from CNBC just so

happened to be published the day after a

shareholder lawsuit against Tesla for

the SolarCity acquisition gave opening

arguments in pursuit of an appeal for a

previous ruling that had gone against

the lawsuit all right moving on from

that something a little bit fun here

from Tesla today they’ve got a new

product that has launched in Europe it

is gigabeer we heard about this when

Tesla opened gigafactory Berlin this is

a five percent ABV pilsner from Tesla in

a cyber truck inspired package and Tesla

says Tesla gigabeer is designed to

emulate the form of cyber truck while

honoring the 500-year tradition of

German Orion Heights Cabot beer making

Tesla says this is a limited edition

pilsner brewed in Berlin with our

exclusive strain of cyber Hops and notes

of citrus Bergamot and sweet fruit each

bottle features a seamless gloss black

sleeve with a glow-in-the-dark Giga

Watermark this is 89 Euros for a pack of

three so it’s not the cheapest beer

you’re ever gonna buy might be the most

expensive and unfortunately for many of

us at this time it does seem to only be

available in Europe

all right last couple of things for

today this Gap has been closing for a

long time but Elon today officially

becoming the most followed person on

Twitter with 133.1 million followers

moving just past Barack Obama at 133

million so congratulations to Elon for

that and since we didn’t talk about

anything else from Elon on Twitter today

now’s probably a good time to do that he

did tweet out that Giga Mexico will have

the lowest water usage per car of any

auto Factory in the world probably no

surprise to those of us that have

followed the company closely all right

lastly then we’ve got a couple of

pricing updates from Ford and from

Porsche Ford has issued another round of

price increases on the Ford F-150

Lightning pro model this is what is

supposed to be the sort of commercial or

work truck that originally started right

around forty thousand dollars but has

now had four significant rounds of price

increases with the most recent one

Happening Now bringing the price from

just under 58 000 up by four thousand

dollars to just under sixty two thousand

dollars now so it’s a pretty sharp

difference in a pretty short period of

time obviously Tesla has faced some

criticism about similar things over the

years and we’ll see what happens with

cyber truck but given the financials

that we have seen from Ford it’s much

harder to see how this was ever a

realistic Target for them than what

we’ve obviously seen transpire in the

financials for Tesla and then also

bucking the price cutting Trends is the

Porsche ticon they have according to the

recap here from Drive Tesla Canada

increased prices on what I believe is

all trims of the ticon by about four to

five percent in the US and Canada for

the 2024 model year so not the most

sensitive category obviously the Porsche

brand very much at play but that does

make the comparison with a Model S that

much more difficult alright that is

where we’ll wrap it up for today then as

always thank you for listening make sure

you’re subscribed and sign up for

notifications you can also find me on

Twitter at teslapodcast and I’ll see you

tomorrow for the Friday March 31st

episode of Tesla daily thank you

[Music]

thank you

Advertisement

反垄断就是瞎胡闹

反垄断的目的是鼓励竞争,但竞争最终的目的就是减少竞争。反垄断最后得到的结果是没有鼓励竞争。竞争者的宿命就是永远都有潜在竞争者。—鲁迅

最近,阿里巴巴115亿罚单,滴滴下架,虎牙收购斗鱼被拒,谷歌脸书一次又一次反垄断起诉。全世界都加入了对大型科技公司反垄断的浪潮。港股科技股萎靡不振。反垄断法的目的是控制资本的无限扩大。当一个公司市场份额不断变大,反垄断机构开始担心,会不会对市场经济,自由竞争,消费者利益构成挑战。假设有多个竞争者,那么他们会因为竞争而压低产品价格,带给消费者利益。假设市场被一个公司垄断,那么这个公司就可以疯狂抬高价格,损害消费者利益,违背自由经济原则。反垄断法也成为了商业的宪法,任何有垄断倾向的并购,都会遭到反垄断部门的诉讼。

创立于1985年的美国DVD租碟公司Blockbuster红极一时,成为了美国最大的影响租借公司。2005年,Blockbuster想要收购当时市场份额排名第三的好莱坞影片租借公司。但美国反垄断部门阻止了这项收购,认为这个收购会增强Blockbuster的垄断地位,不利于竞争。但他们不知道的是网络直播公司奈飞NETFLIX的迅速崛起,给Blockbuster造成严重的威胁。反垄断部门干涉了Blockbuster的正常资金的投资和运营,干涉了自由市场。结局是这个所谓的垄断公司在未来几年果不其然江河日下,直到倒闭。反垄断部门那些所谓高瞻远瞩的执政者去决定什么能合并,什么不能合并,就正如你要皇帝去决定每个县包子的价格,最终造成的是破坏市场经济。

传统观点认为垄断企业会利用价格战打击弱小企业,等杀死这些企业后,垄断者会开始大幅度调高价格剥削消费者。然而,这在现实中是不会发生的。比如一个小镇上有个按摩店,因为价格公道,技艺娴熟,他打败了所有其他的按摩店,垄断了小镇的按摩业,让其他店全部倒闭。此时他把价格升了一倍。盈利疯狂上涨,老板睡着都能笑出声。但没过一周,一个做包子的叫乐乐耳子的男人看到了按摩行业可以如此赚钱,他立马联系了之前搞按摩的嘉琪霸霸,开了一家新的按摩店。价格只是垄断按摩店的一半。在新的按摩店占据市场1%的份额后,垄断按摩店觉得形势不对。为了杀死耳子和霸霸的店,把按摩价格降到比人工还低的亏本价格。3个月后,新按摩店倒闭。但垄断按摩店赔了3个月99%市场份额的利润,还要倒贴亏损的钱。把新店杀死后。他们接下来又调回了双倍的价格,想要弥补损失。这时,又有一家新店出现。。。。。这种以价格战消灭对手的方式最终是什么结局相信不难想到。

我们生活中实际看到的那些垄断企业非但没有抬升价格,反而拼命的降低价格。比如微信,他如此垄断,为什么不去收个月费?因为一个垄断企业想要保持他的垄断地位的唯一方法,是不断加强他和其他企业之间的护城河,通过加强管理与创新,给与消费者更物美价廉的商品。

19世纪末美国,洛克菲勒的标准石油公司在石油提炼成煤油过程中做了极大的创新。当时提炼的技术只能把60%的石油变成煤油。其他40%只能当废品倒入大海。而他却发明出了利用这40%废油的创新产品的方法,比如制作肥料,润滑剂,油漆,蜡烛,凡士林。这些副产品的销售极大降低了他的煤油生产总成本。以至于他可以给出其他所有竞争者无法匹敌的价格。1880年,他们占据了美国95%的市场,在如此垄断的情况下,在1880的前后10年间。他们的出售煤油却从1美金每加仑降了90%到10美分每加仑。这个所谓的垄断者保护了环境,降低了煤油价格,提高了人们生活水平,创造了无数的工作岗位。

你可能觉得也许是洛克菲勒是心地善良,所以降低价格,然而并不是。因为就像课本里讲的一样,资本从来是贪婪地。但洛克菲勒都垄断了为什么又要降低价格如此的讨好消费者呢。因为如果他不这么做,他就会失去他垄断的地位,永远都会有隐藏中的竞争者。当黑莓垄断手机市场的时候,搞电脑的苹果却突然杀入手机市场,夺取了半壁江上,后来安卓又一军突起,掠夺苹果份额。马化腾的QQ差点被雷军的米聊干掉,好在千钧一发之际祭出了微信。马云2014年员工大会上说,如果你们不努力,2013年将是阿里巴巴历史上最好的一年。这些所谓垄断企业对竞争者的恐惧要远远大于我们对于他们提升价格的恐惧。市场上不存在永远的垄断者,在风口浪尖的自由市场,逆水行舟,不创新不进步不去更讨好消费者,再垄断未来也就是死路一条。反垄断打破了自由经济的运作,垄断企业连定价都手足无措,价格调高,是以垄断姿态剥削消费者;降低价格,是打价格战;定个价格不高不低,不升不降,有人会去指责你这叫合谋性价格,也就是联手抬高价格。 综上。反垄断法实际是去强制保护被竞争淘汰下来的失败者。供应商提供廉价的服务本来是值得鼓励的,因为竞争使得消费者得益了,但是反垄断法的执行者,同时又去惩罚那些所谓的掠夺性定价行为或者说倾销的行为,而事实上,掠夺性定价或者倾销行为,是不能够使得厂商获得垄断地位的。日常生活中,我们见到的所谓掠夺性定价行为、倾销行为,往往不是出于垄断的意图,而是出于生产者效率的提高。说别人进行掠夺性定价、说别人倾销,往往是市场当中成本更高的生产者,指责更成功的竞争对手的一种借口。但反垄断法的执法者,往往又站到了这些在市场竞争当中失败的一方,组织他们被自由经济淘汰。

小岛经济学-1.经济是如何增长的

经济增长的原因

CS小岛上有两个渔民: 嘉琪霸霸、乐乐耳子。他们每天各只能抓一条鱼,刚好供他们各自一天的温饱。有一天嘉琪霸霸决定不苟且与此,他还想要诗和远方。他决定饿一天肚子,做一个渔网。渔网如果能做成,他每天可以捕两条鱼。这样他就可以工作一天,另一天去享受生活了。乐乐耳子摸着自己的胖肚肚笑道:“霸霸你肯定会失败的,到时我可不会管你”。霸霸不顾耳子嘲笑,竟然在第二天做出了渔网。从此霸霸一天可以补两条鱼,过上了工作一天休息一天的生活。小岛一天的总捕鱼量变成了三条,经济得到了增长。总结这个列子,CS小岛经济的长期增长靠的是霸霸的创新意识,创造出的渔网工具和他忍饥挨饿一天所得到的时间资本

借贷让经济加速发展

乐乐耳子看到霸霸一天能补两条鱼,哈喇子都滴到了地上,想要借渔网一用。但霸霸不愿意,因为渔网就只有一个,说:“你可以自己去做一个新的”。但乐乐耳子实在不想饿肚子,提议道:“不如你借我一条鱼,我到时换你两条”。霸霸同意了。乐乐用霸霸借给的一条鱼的资本做出了小岛第二个网。通过一条鱼的借贷,CS岛生产力从3条鱼变成了4条鱼。

万恶的资本主义….?

现实中,有很多仇富的人。“比尔盖茨,扎克伯格,凭什么你们好像不用干什么,却那么有钱。我拼死拼活,才这么一点钱。世界简直太不公平了!”。 “那些有钱人都自私的把钱存着自己享用,社会上那么多穷人他们却视而不见!”。其实真相是这样吗?

在霸霸拥有渔网和鱼,成为了一个小富人后,他可以干4件事。第一:每天把多出来的鱼自己吃掉,享受人生;第二:存起来。万一以后鱼少了到时可以应急。第三:把渔网借给乐乐耳子,要求乐乐耳子每天上交半条鱼给霸霸。第四,借给乐乐耳子一条鱼,让他自己去造渔网,但要求乐乐还两条鱼。

霸霸如何才能成为一个世界首富,拥有百万条鱼的渔翁呢?

一定不是把自己多出的鱼自己的存起来自己吃,这样鱼反而会越来越少。他必须把鱼或者网借出去给别人。帮助别人,也帮助自己捕鱼。然后用多的鱼再造新的网,再借给新的人。反复下去。第三第四件事乍看起来很剥削乐乐耳子。但其实,乐乐耳子的生活变的更好了,每天能吃得鱼更多了,肚子可以更大了。上面4件的哪一件事,其实都不影响他人,没有剥削任何人的财富,反而为别人创造了财富。

 想象生活中仇富的人,也许正因为有了他们,你才能过现在的生活。他的富有并不是来源于对你的剥夺,反而,你因为他的更有钱也变得更有钱了。

为什么需要投资实体黄金而不是ETF

很多人觉得黄金基金流动性好,方便买卖,也没有被盗的风险。管理费也不贵。所以都去买黄金基金。比如世界最大的黄金基金SLD,最大的白银基金SLV。或者国内支付宝里也可以购买博时黄金,华安黄金。这些基金对于短期投资很不错,ZLL借用杠杆炒纸黄金几天赚了10几万。但对于长期投资来说,其实里面存在着很大的风险。

黄金基金的运作方式

购买黄金基金不等于真的购买黄金。你买的等同于一个公司的股票。正常来说,买的人多了,股价上涨,买的人少,股价下跌。那黄金基金是如何做到跟踪黄金价格而忽略购买需求的呢?在你去购买了100股黄金基金后。他们会增发100股,去稀释掉你的买入带来的对股价的变化。所以股价不受你买入的影响。他们会用你这100股的钱去买一定数量的实体或期货黄金。过了几天,你发现黄金价格上涨,把这100股卖出。黄金基金会把他当时买入的实体黄金或者期货给卖掉。用这个卖掉的钱赎回你卖掉的那100股。那么这样,基金的股票价格就不会因为你把股票卖了而降低。而会始终跟踪着黄金价格变动。

黄金基金的危险

假设,黄金基金把所有投资人的钱都去买实体黄金。那这个模式就不存在任何问题。在经济危机来临后。他们只需要把实体黄金兑换成现金,就能保证他们的股价能准确跟踪黄金的价格。但是,黄金基金并不会把所有你买入他们股票的钱拿去买实体的黄金。他们成立的目的是为了赚钱。他们和银行一样。用的是杠杆模式的《部分准备金制度》。​你存钱进银行,银行留下10%的钱给你平时去取,剩下90%全部去借贷给别人赚钱。同样,黄金基金只用了小一部分去买黄金。​大部分的钱去用于别的商业用途。这个模式在经济正常的情况下没有问题。​但还记得2008年次贷危机有多少银行倒闭吗?

当下,各国政府疯狂借贷印钱,0利率使得整个金融体系过度的杠杆化,债务与收入的不匹配不断加大。灰犀牛其实就在不远处。当到了杠杆经济周期的最顶端。借贷,杠杆金融衍生品开始崩塌。流通的信贷会开始去杠杆化,整个经济通货紧缩。银行企业及各种经融机构开始倒闭。股票开始被大量抛售。黄金基金也不例外,他们手上只持有的少量的实体黄金,当现金出现短缺。他们没有足够黄金去兑换现金,去赎回你卖出的股票。造成他们的股价没有办法继续追踪黄金的价格。一个黄金基金持有的实体黄金越少,那么在特殊时期来临时,你所遭受的风险就越大。最后,当实体黄金突飞猛进开始往上涨后,也许你的黄金基金还在不停的往下跌。​

最后总结,不是你握在手上的黄金,那么不是你的黄金。

Invest safe.

记录生活

今天的柔术实战比上周六感觉体力好多了。。上周六的简直天旋地转。。拉了老王和JASON一起去,一定要想办法说服他们一直去。。

SIDE CONTROL ESCAPE还是不行,稍微会防了点,知道两手要CONNECT,还继续学YOUTUBE吧

 

 

睡成外星人的阿呆

%e7%85%a7%e7%89%87-16-9-8-%e4%b8%8b%e5%8d%887-41-30

REST constraints

• It must be a client-server system
• It has to be stateless—there should be no need for the service to keep users’
sessions; in other words, each request should be independent of others
• It has to support a caching system—the network infrastructure should
support cache at different levels
• It has to be uniformly accessible—each resource must have a unique address
and a valid point of access
• It has to be layered—it must support scalability
• It should provide code on demand—although this is an optional constraint,
applications can be extendable at runtime by allowing the downloading of
code on demand, for example, Java Applets

Coding styles – efficient code writing

The Single Responsibility Principle 
THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE

Click to access srp.pdf

one class should only have one responsibility. for example, in a server and client example. Client might have functions of make connection and sending messages. it sounds perfect reasonable but it actually has two responsibilities. The drawback of this is 1. eg when two different application use this class. one might only use the connecting function whereas the other one using chatting function. they have to include both codes in when compile. 2 when they change some code for connection method. it might result chatting function in class not working.

The Open-Closed Principle
http://www.objectmentor.com/resources/articles/ocp.pdf

A method should be deigned open to the extension but closed for the modification. The key is using abstraction. For example, you might have a method of drawShapes(ShapeType shapeType). in the method, you have case “SQUARE”, case “RECTANGLE” and so on. To add a CIRCLE in, you will have to edit the method body. Instead, you can have a interface of Shape, using add(Shape shape) to add in additional shapes. then iterate the list and draw the shapes. in this way, the principle is maintained.

Java Synchronization Tutorial : What, How and Why? Read more: http://javarevisited.blogspot.com/2011/04/synchronization-in-java-synchronized.html#ixzz3ilDfAUs9

Multit-hreading and synchronization is a very important topic for any Java programmer. Good knowledge of multithreading, synchronization, and thread-safety can put you in front of other developers, at same time it’s not easy to master these concept. In fact writing correct concurrent code is one of the hardest thing, even in Java, which has several inbuilt synchronization utilities. In this Java synchronization tutorial we will learn what is meaning of Synchronization in Java, Why do we need Synchronization in Java, What is java synchronized keyword, examples of using Java synchronized method and blocks, What can happen in multithreading code in absence of synchronized constructs, tips to avoid mistakes, while locking critical section in Java and some of importantpoints about synchronization in Java. Since Java provides different constructs to provide synchronization and locking e.g. volatile keyword, atomic variable, explicitly locking using java.util.concurrent.lock.Lock interface and there popular implementations e.g. ReentrantLock and ReentrantReadWriteLock, It becomes even more important to understand difference between synchronized and other constructs. Remember, clear understanding of synchronization is must to write correct concurrent code in Java, which is free of multithreading issues like deadlock, race conditions and thread-safety. I am sure, things learned in this Java synchronization tutorial will help. Once you gone through this article, You can further read Java Concurrency in Practice to develop your concept.  That’s the one of those book which every Java developer must read.

What is Synchronization in Java

Synchronization in Java is an important concept since Java is a multi-threaded language where multiple threads run in parallel to complete program execution. In multi-threaded environment synchronization of Java object or synchronization of Java class becomes extremely important. Synchronization in Java is possible by using Java keywords “synchronized” and “volatile”. Concurrent access of shared objects in Java introduces to kind of errors: thread interference and memory consistency errors and to avoid these errors you need to properly synchronize your Java object to allow mutual exclusive access of critical section to two threads. By the way This Java Synchronization tutorial is in continuation of my article How HashMap works in Java  and difference between HashMap and Hashtable in Java  if you haven’t read already you may find some useful information based on my experience in Java Collections.

Why do we need Synchronization in Java?

If your code is executing in multi-threaded environment, you need synchronization for objects, which are shared among multiple threads, to avoid any corruption of state or any kind of unexpected behavior. Synchronization in Java will only be needed if shared object is mutable. if your shared object is either read only or immutable object, than you don’t need synchronization, despite running multiple threads. Same is true with what threads are doing with object if all the threads are only reading value then you don’t require synchronization in Java. JVM guarantees that Java synchronized code will only be executed by one thread at a time. In Summary Java synchronized Keyword provides following functionality essential for concurrent programming :

1) synchronized keyword in Java provides locking, which ensures mutual exclusive access of shared resource and prevent data race.

2) synchronized keyword also prevent reordering of code statement by compiler which can cause subtle concurrent issue if we don’t use synchronized or volatile keyword.

3) synchronized keyword involve locking and unlocking. before entering into synchronized method or block thread needs to acquire the lock, at this point it reads data from main memory than cache and when it release the lock, it flushes write operation into main memory which eliminates memory inconsistency errors.

Synchronized keyword in Java

Prior to Java 1.5 synchronized keyword was only way to provide synchronization of shared object in Java. Any code written by using  synchronized block or enclosed inside synchronized method will be mutually exclusive, and can only be executed by one thread at a time. You can have both static synchronized method and non static synchronized method and synchronized blocks in Java but we can not have synchronized variable in java. Using synchronized keyword with variable is illegal and will result in compilation error. Instead of synchronized variable in Java, you can have java volatile variable, which will instruct JVM threads to read value of volatile variable from main memory and don’t cache it locally. Block synchronization in Java is preferred over method synchronization in Java because by using block synchronization, you only need to lock the critical section of code instead of whole method. Since synchronization in Java comes with cost of performance, we need to synchronize only part of code which absolutely needs to be synchronized.

Example of Synchronized Method in Java

Using synchronized keyword along with method is easy just apply synchronized keyword in front of method. What we need to take care is that static synchronized method locked on class object lock and non static synchronized method locks on current object (this). So it’s possible that both static and non static java synchronized method running in parallel.  This is the common mistake a naive developer do while writing Java synchronized code.

public class Counter{ private static int count = 0; public static synchronized int getCount(){ return count; } public synchoronized setCount(int count){ this.count = count; } }

In this example of Java synchronization code is not properly synchronized because both getCount() and setCount() are not getting locked on same object and can run in parallel which may results in incorrect count. Here getCount() will lock inCounter.class object while setCount() will lock on current object (this). To make this code properly synchronized in Java you need to either make both method static or non static or use java synchronized block instead of java synchronized method.By the way this is one of the common mistake Java developers make while synchronizing their code.

Example of Synchronized Block in Java

Using synchronized block in java is also similar to using synchronized keyword in methods. Only important thing to note here is that if object used to lock synchronized block of code, Singleton.class in below example is null then Java synchronized block will throw a NullPointerException.

public class Singleton{ private static volatile Singleton _instance; public static Singleton getInstance(){ if(_instance == null){ synchronized(Singleton.class){ if(_instance == null) _instance = new Singleton(); } } return _instance; }

This is a classic example of double checked locking in Singleton. In this example of Java synchronized code, we have made only critical section (part of code which is creating instance of singleton) synchronized and saved some performance. If you make wholemethod synchronized than every call of this method will be blocked, while you only need blocking to create singleton instance on first call. By the way, this is not the only way to write threadsafe singleton in Java. You can use Enum, or lazy loading to avoid thread-safety issue during instantiation. Even above code will not behave as expected because prior to Java 1.5, double checked locking was broker and even with volatile variable you can view half initialized object. Introduction of Java memory model and happens before guarantee in Java 5 solves this issue. To read more about Singleton in Java see that.

Important points of synchronized keyword in Java

  1. Synchronized keyword in Java is used to provide mutual exclusive access of a shared resource with multiple threads in Java. Synchronization in Java guarantees that, no two threads can execute a synchronized methodwhich requires same lock simultaneously or concurrently.
  1. You can use java synchronized keyword only on synchronized method or synchronized block.
  1. When ever a thread enters into java synchronized method or block it acquires a lock and whenever it leaves java synchronized method or block it releases the lock. Lock is released even if thread leaves synchronizedmethod after completion or due to any Error or Exception.
  1. Java Thread acquires an object level lock when it enters into an instance synchronized java method and acquires a class level lock when it enters into static synchronized java method.
  1. Java synchronized keyword is re-entrant in nature it means if a java synchronized method calls another synchronized method which requires same lock then current thread which is holding lock can enter into that method without acquiring lock.
  1. Java Synchronization will throw NullPointerException if object used in java synchronized block is null e.g. synchronized (myInstance) will throws java.lang.NullPointerException if myInstance is null.
  1. One Major disadvantage of Java synchronized keyword is that it doesn’t allow concurrent read, which can potentially limit scalability. By using concept of lock stripping and using different locks for reading and writing, you can overcome this limitation of synchronized in Java. You will be glad to know that java.util.concurrent.locks.ReentrantReadWriteLock provides ready made implementation of ReadWriteLock in Java.
  1. One more limitation of java synchronized keyword is that it can only be used to control access of shared object within the same JVM. If you have more than one JVM and need to synchronized access to a shared file system or database, the Javasynchronized keyword is not at all sufficient. You need to implement a kind of global lock for that.
  1. Java synchronized keyword incurs performance cost. Synchronized method in Java is very slow and can degrade performance. So use synchronization in java when it absolutely requires and consider using java synchronized block for synchronizing critical section only.
  1. Java synchronized block is better than java synchronized method in Java because by using synchronized block you can only lock critical section of code and avoid locking whole method which can possibly degrade performance. A good example of java synchronization around this concept is getInstance() method Singleton class. See here.
  1. Its possible that both static synchronized and non static synchronized method can run simultaneously or concurrently because they lock on different object.
  1. From java 5 after change in Java memory model reads and writes are atomic for all variables declared using volatile keyword (including long and double variables) and simple atomic variable access is more efficient instead of accessing these variables via synchronized java code. But it requires more care and attention from the programmer to avoid memory consistency errors.
  1. Java synchronized code could result in deadlock or starvation while accessing by multiple thread if synchronization is not implemented correctly. To know how to avoid deadlock in java see here.
  1. According to the Java language specification you can not use Java synchronized keyword with constructor it’s illegal and result in compilation error. So you can not synchronized constructor in Java which seems logical because other threads cannot see the object being created until the thread creating it has finished it.
  1. You cannot apply java synchronized keyword with variables and can not use java volatile keyword with method.
  1. Java.util.concurrent.locks extends capability provided by java synchronized keyword for writing more sophisticated programs since they offer more capabilities e.g. Reentrancy and interruptible locks.
  1. Java synchronized keyword also synchronizes memory. In fact java synchronized synchronizes the whole of thread memory with main memory.
  1. Important method related to synchronization in Java are wait(), notify() and notifyAll() which is defined in Object class. Do you know, why they are defined in java.lang.object class instead of java.lang.Thread? You can find some reasons, which make sense.
  2. Do not synchronize on non final field on synchronized block in Java. because reference of non final field may change any time and then different thread might synchronizing on different objects i.e. no synchronization at all. example of synchronizing on non final field :

private String lock = new String(“lock”); synchronized(lock){ System.out.println(“locking on :” + lock); }

any if you write synchronized code like above in java you may get warning “Synchronization on non-final field”  in IDE like Netbeans and InteliJ

  1. Its not recommended to use String object as lock in java synchronized block because string is immutable object and literal string and interned string gets stored in String pool. so by any chance if any other part of code or any third party library used same String as there lock then they both will be locked on same object despite being completely unrelated which could result in unexpected behavior and bad performance. instead of String object its advised to use new Object() for Synchronization in Java on synchronized block.

private static final String LOCK = “lock”; //not recommended private static final Object OBJ_LOCK = new Object(); //better public void process() { synchronized(LOCK) { …….. } }

  1. From Java library Calendar and SimpleDateFormat classes are not thread-safe and requires external synchronization in Java to be used in multi-threaded environment.

Probably most important point about Synchronization in Java is that, in the absence of synchronized keyword or other construct e.g. volatile variable or atomic variable, compiler, JVM and hardware are free to make optimization, assumption, reordering or caching of code and data, which can cause subtle concurrency bugs in code. By introducing synchronization by using volatile, atomic variable or synchronized keyword, we instruct compiler and JVM to not to do that.
Update 1: Recently I have been reading several Java Synchronization and Concurrency articles in internet and I come across jeremymanson’s blog which works in google and has worked on JSR 133 Java Memory Model, I would recommend some of this blog post for every java developer, he has covered certain details about concurrent programming , synchronization and volatility in simple and easy to understand language, here is the link atomicity, visibility and ordering.

Update 2:  I am grateful to my readers, who has left some insightful comments on this post. They have shared lots of good information and experience and to provide them more exposure, I am including some of there comments on main article, to benefit new readers.

@Vikas wrote
Good comprehensive article about synchronized keyword in Java. to be honest I have never read all these details about synchronized block or method at one place. you may want to highlight some limitation of synchronized keyword in Java which is addressed by explicit locking using new concurrent package and Lock interface :

1. synchronized keyword doesn’t allow separate locks for reading and writing. as we know that multiple thread can read without affecting thread-safety of class, synchronized keyword suffer performance due to contention in case of multiple reader and one or few writer.

2. if one thread is waiting for lock then there is no way to time out, thread can wait indefinitely for lock.

  1. on similar note if thread is waiting for lock to acquired there is no way to interrupt the thread.

All these limitation of synchronized keyword is addressed and resolved by using ReadWriteLock and ReentrantLock in Java 5.

@George wrote
Just my 2 cents on your great list of Java Synchronization facts and best practices :
1) synchronized keyword in internally implemented using two byte code instructions MonitorEnter and MonitorExit, this is generated by compiler. Compiler also ensures that there must be a MonitorExit for every MonitorEnter in different code path e.g. normal execution and abrupt execution, because of Exception.

2) java.util.concurrent package different locking mechanism than provided by synchronized keyword, they mostly used ReentrantLock, which internally use CAS operations, volatile variables and atomic variables to get better performance.
3) With synchronized keyword, you have to leave the lock, once you exist a synchronized method or block, there is no way you can take the lock to other method. java.util.concurrent.locks.ReentrantLock solves this problem by providing control for acquiring and releasing lock, which means you can acquire lock in method A and can release in method B, if they both needs to be locked in same object lock. Though this could be risky as compiler will neither check nor warn you about any accidental leak of locks. Which means, this can potentially block other threads, which are waiting for same lock.

4) Prefer ReentrantLock over synchronized keyword, it provides more control on lock acquisition, lock release and better performance compared to synchronized keyword.
5) Any thread trying to acquire lock using synchronized method will block indefinitely, until lock is available. Instead this, tryLock() method of java.util.concurrent.locks.ReentrantLock will not block if lock is not available.
Having said that, I must say, lots of good information.

Recommend Books to learn Synchronization and Concurrency in Java

Synchronization and Concurrency is complex topic in Java and it’s not easy to master them. Even more experienced Java developers struggle to write correct concurrent code in Java. I would highly recommend following Java books to master multi-threading, synchronization and Concurrency.

Read more: http://javarevisited.blogspot.com/2011/04/synchronization-in-java-synchronized.html#ixzz3ilDqjVzf

Motherboard Port Guide: Solving Your Connector Mystery

If you’ve ever opened a PC case and stared inside, or looked at a bare motherboard, you may be taken aback by the number and variety of connectors, pins, and slots that exist on a modern PC motherboard. In this guide I’ll identify some of the most common (and a few uncommon) connectors on motherboards used in most home PCs. I won’t cover server- or workstation-class boards here, just what you might find in a typical midrange or high-end home PC.

For a similar discussion of the ports that you’re likely to encounter on the exterior of a PC case, see “Multiple Ports on Your PC: What Do They Do for You?

Since no single motherboard contains every type of connectors, I’ve used photos of four different boards to illustrate key examples. In one or two instances, there is some overlap; but for the most part, connectors are mentioned only once. Many of them may exist across different motherboard designs, however.

ADVERTISING

Asus P5WDH Deluxe

Let’s start with an older motherboard, an Asus P5WDH Deluxe. This motherboard has a few connectors that aren’t included on current-generation boards, as wll as some that do are still included, but are more readily visible here.

Connections on an older Asus P5WDH Deluxe motherboard.

Audio front panel: This ten-pin connector links to the front-panel headphone and microphone inputs. The particular connector shown is an AC97 connector, which existed prior to multichannel HD audio. It’s still in common use today.

Azalia digital audio header: You rarely find this connector, used to tie the motherboard to multichannel digital outputs on the case, on current motherboards.

Serial-port header: This connector isn’t physically present on the board shown–you can just see the solder points for it. But this header does appear on a few modern boards. It supports a nine-pin, RS-232 serial port, usually as a bracket that occupies a slot space on the back of the case. A number of RS-232 connections remain in use today, mostly in point-of-sale devices or specialized test instruments. Consumer boards typically don’t have them.

FireWire (IEEE 1994a): Once common as a digital camcorder interface, FireWire has largely been supplanted by USB, and the motherboard makers are gradually phasing it out. Some professional audio hardware still uses FireWire, though; you may also occasionally find higher-speed IEEE 1394b headers, but they are even rarer.

USB 2.0 front panel: These connectors are used to link to the front-panel USB ports on PC cases.

SATA connectors: These components connect via cables to various storage devices, including hard-disk drives, solid-state drives, and optical drives.

IDE connector: Rarely found today, IDE connectors were used to link to older hard drives. In addition, until a couple of years ago, many optical drives supported IDE. Today, all new storage devices ship with SATA.

Floppy disk connector: The venerable 3.5-inch floppy disk drive survived for nearly two decades–an eternity in the tech universe. But unless you have a pile of old floppies, you won’t need a floppy drive. And if you do find yourself needing a floppy drive, you can always pick up an external, USB-connected drive.

Intel DP67BG

Now let’s examine a more recent motherboard: an Intel D67BG, based on Intel’s P67 chipset and supporting LGA 1155 CPUs (like the Sandy Bridge-based Core i7-2600K).

Intel D67BG motherboard: a modern Intel design.

DDR3 memory sockets: Current-generation PC systems use DDR3 memory, but in many instances they support different operating speeds. The P67 chipset used in this board maxes out at DDR3-1600, but to achieve that level of speed you’d have to overclock the chipset–officially the P67 supports only DDR3-1333. Here, we see four memory sockets. The system supports dual-channel memory, meaning that the system is populated with paired memory modules, which are mounted in sockets of the same color.

CPU fan header: This connector is specifically designed to link to the CPU cooling fan. The system BIOS monitors CPU cooling fan speeds; and if the fan isn’t connected to this header, you may get an error at bootup.

Eight-pin ATX12V (CPU power) connector: Back when the Pentium 4 processor first shipped, Intel realized that high-performance CPUs needed their own source of clean, dedicated power beyond what the standard 24-pin power connector could deliver. Thus was born ATX12V. You’ll see four-pin connectors on lower-end boards supporting CPUs with lower thermal design power (TDP), but the eight-pin version of the connector is used with higher-end processors and on boards that users may overclock.

Power for secondary fans: Many motherboards with secondary-fan power headers; these connectors are mainly used to power and monitor various case fans.

PCI Express x1 connector: PCI Express is a serial interface, though multiple lanes may be ganged together. The “x1” refers to a slot supporting a single PCI Express lane; it is used for I/O devices that don’t require bidirectional bandwidth greater than 500 megabytes per second (gen 1 PCIe). Sound cards, for example, are typically PCIe x1 devices.

PCI Express x16 (graphics): PCI Express x16 slots are used mostly for graphics cards, though they can be used with any PCI Express card. Confusion may arise, however, because not all PCIe x16 slots are true PCIe x16. Occasionaly, you’ll see PCIe x16 connectors that are physical slots for accommodating graphics cards, but are actually eight-lane (x8) or even four-lane (x4) electrically.

On some boards, even slots that support true 16-lane PCI Express for graphics may revert to eight lanes if you install a second graphics card into a second PCIe x16 slot on the motherboard. The P67 chipset, for instance, has only 16 total PCIe lanes for graphics. So if you drop in two graphics cards to run in dual GPU mode, each card will have just eight lanes available to it. This situation isn’t as bad as it sounds, though, since even eight lanes in a PCIe 2.0- or 3.0-based system delivers plenty of bandwidth for most games.

32-bit legacy PCI slot: The now-classic 32-bit PCI slot has been around since 1993. A host of expansion cards support 32-bit PCI; and to accommodate them, most motherboards are likely to have at least one 32-bit PCI slot going forward. You may see some system boards configured so that a particular back-panel case bracket can support either a PCI slot or a PCIe slot, with some overlap between the two because they’re very close together.

Front-panel switch header: This header connects various wires to the front panel of the case, where they link to power and reset buttons, and status LEDs for power and storage-drive activity.

Gigabyte 990FXA-UD7

Next we’ll turn our attention to a motherboard that supports AMD CPUs. Note that AMD-chipset boards support many of the same features as Intel-based boards–that’s the great thing about industry standards.

An AMD-compatible motherboard: the Gigabyte 990FXA-UD7.

24-pin ATX power: This connector exists on all current ATX-based motherboards, and is the standard means of connecting power from power supplies. This connector delivers power to all interfaces, including 3V, 5V, and 12V. The typical ATX12V version 2.3 PSU delivers up to 75W for PCI Express graphics cards; but numerous modern graphics cards need more than that, which is why you’ll often find secondary six- or eight-pin power connectors on the graphics cards themselves.

ATX4P: This unusual item is actually a SATA power connector for delivering power to SSDs, hard drives, or optical drives from the motherboard itself.

TPM connector: Some off-the-shelf PCs and laptops use the Trusted Platform Module connector to link to a cryptographic processor module for storing encryption keys and handling dedicated encryption chores such as hard-drive encryption and certain types of digital rights management (DRM) decryption.

USB 3.0 front panel: This connector is used to drive front-panel USB 3.0 connectors. It requires more pins than USB 2.0 connectors do, but it drives two USB 3.0 ports instead of one. If your PC case lacks a USB 3.0 internal cable, you won’t be able to use it. Like back-panel connectors, front-panel USB 3.0 ports are often color-coded blue.

AMD CPU socket: I’m calling out this component because its style differs from that of a modern Intel CPU socket. AMD CPUs still have pins, whereas Intel has moved the pins to the motherboard socket.

Intel DZ77GA-70K

I’m using a photo of just one section of this board, to call out some specific connectors and to get a little closer in. The Intel DZ77GA-70K motherboard is designed to accommodate the latest Intel Z77 chipset.

Part of the Intel DZ77GA-70K–a motherboard that hosts the latest Intel Z77 chipset.

Case fan header: As noted earlier, most higher-end motherboards have several of these fan headers scattered around the board. If enough of them are available, you should connect your fans to them, so that the BIOS can monitor and manage the fan speeds–unless you’re a serious overclocker who uses separate fan-control modules.

PCI Express x4 slot: This relatively rare physical and electrical PCIe x4 slot is used for higher-performance networking cards and for some storage controller cards.

S/PDIF digital audio: This older type of connector was originally used to connect to CD-ROM drives. Today it’s still used to connect to some optical drives and other audio devices that support S/PDIF (Sony/Philips Digital Interface) digital audio.

USB 3.0 front panel: The DZ77GA motherboard ships with two front-panel USB 3.0 connectors, driving up to four USB 3.0 ports on the front of the PC case.

High-current USB 2.0 front panel: This is a slightly different type of USB 2.0 connector. Though it acts as a normal USB 2.0 port when sending or receiving data, it can deliver extra current to permit fast charging of mobile devices, and it can even charge devices (like Apple’s iPad) that requires more current than standard USB 2.0 normally delivers.

Consumer IR: This connector is used to attach front-panel infrared receivers, which enable users to control the PC via a standard programmable remote.

Diagnostic LEDs: Most motherboards have simple LEDs that light up or change color if the board experiences problems. A few higher-end boards, however, have these status LEDs, which flash an alphanumeric code that helps the user narrow down the source of a boot problem.

That wraps up our tour of various motherboard connectors, pins, and ports. Though I haven’t covered all of the possibilities by any means, the ones listed here account for the vast majority of connectors you’ll encounter on today’s motherboards.

Rarely will you use every single connector on a board, but understanding these connectors should help you choose a PC case that suits your needs, or that accommodates new devices that you plan to add in an upgrade. Also, if you have a specific need, you’ll be better able to shop for a motherboard capable of handling your application.