休眠性能提示:臟收集效果

在使用Hibernate作為ORM開發服務器和嵌入式應用程序8年后,我全力以赴地尋求提高Hibernate性能的解決方案,閱讀博客和參加會議,我決定與您分享這幾年獲得的知識。

這是更多新帖子中的第一篇:

去年,我以Devoxx的身份參加了演講,但我也參加了有關休眠反模式的 Patrycja Wegrzynowicz會議。 在該演示中, Patrycja向我們展示了一種反模式,這種模式令我震驚,因為事實證明它預料到了意外情況。

我們將看到當Hibernate檢測到一個骯臟的集合并應該重新創建它時所產生的效果。

讓我們從將要使用的模型開始,只有兩個與一對多關聯相關的類:

@Entity
public class Starship {private Long id;@Id @GeneratedValue(strategy=GenerationType.SEQUENCE) public Long getId() {return id;}public void setId(Long id) {this.id = id;}private Date launched;@Temporal(TemporalType.DATE)  public Date getLaunched() {return launched;}public void setLaunched(Date launched) {this.launched = launched;}private String registry;@Column(unique=true, nullable=false) public String getRegistry() {return registry;}public void setRegistry(String registry) {this.registry = registry;}private StarshipClassEnum starshipClassEnum;@Enumerated public StarshipClassEnum getStarshipClassEnum() {return starshipClassEnum;}public void setStarshipClassEnum(StarshipClassEnum starshipClassEnum) {this.starshipClassEnum = starshipClassEnum;}private AffiliationEnum affiliationEnum;@Enumerated public AffiliationEnum getAffiliationEnum() {return affiliationEnum;}public void setAffiliationEnum(AffiliationEnum affiliationEnum) {this.affiliationEnum = affiliationEnum;}private Physics physics;@Embedded public Physics getPhysics() {return physics;}public void setPhysics(Physics physics) {this.physics = physics;}private List<Officer> officers = new ArrayList<Officer>();@OneToMany(cascade={CascadeType.ALL}) public List<Officer> getOfficers() {return Collections.unmodifiableList(officers);}protected void setOfficers(List<Officer> officers) {this.officers = officers;}public void addOfficer(Officer officer) {officer.setStarship(this);this.officers.add(officer);}public Starship() {super();}public Starship(String registry) {setRegistry(registry);}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result+ ((registry == null) ? 0 : registry.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Starship other = (Starship) obj;if (registry == null) {if (other.registry != null)return false;} else if (!registry.equals(other.registry))return false;return true;}
}
@Entity
public class Officer {private Long id;@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)public Long getId() {return id;}protected void setId(Long id) {this.id = id;}private String name;@Column(unique=true, nullable=false) public String getName() {return this.name;}public void setName(String name) {this.name = name;}private SpeciesEnum speciesEnum;@Enumerated public SpeciesEnum getSpeciesEnum() {return speciesEnum;}public void setSpeciesEnum(SpeciesEnum speciesEnum) {this.speciesEnum = speciesEnum;}private PlanetEnum homePlanet;@Enumerated public PlanetEnum getHomePlanet() {return homePlanet;}public void setHomePlanet(PlanetEnum homePlanet) {this.homePlanet = homePlanet;}private AffiliationEnum affiliationEnum;@Enumerated public AffiliationEnum getAffiliationEnum() {return affiliationEnum;}public void setAffiliationEnum(AffiliationEnum affiliationEnum) {this.affiliationEnum = affiliationEnum;}private RankEnum rank;@Enumerated @NotNull public RankEnum getRank() {return rank;}public void setRank(RankEnum rank) {this.rank = rank;}private Starship starship; @ManyToOne public Starship getStarship() {return starship;}protected void setStarship(Starship starship) {this.starship = starship;}public Officer() {super();}public Officer(String name, RankEnum rank) {setName(name);setRank(rank);}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + ((name == null) ? 0 : name.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Officer other = (Officer) obj;if (name == null) {if (other.name != null)return false;} else if (!name.equals(other.name))return false;return true;}}

在上一堂課中,我們應注意三個重點:

  • 我們在屬性級別而不是字段級別進行注釋。
  • @ OneToMany和@ ManyToOne使用默認選項( 級聯定義除外)
  • 星際飛船類的軍官getter返回一個不變的列表。

為了測試模型配置,我們將創建一個測試,該測試創建并保留一個Starship和七個高級管理人員 ,并在不同的TransactionEntityManager中找到創建的Starship

@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class StarshipPersistenceTests {@Injectprivate EntityManagerFactory entityManagerFactory;@Testpublic void testSaveOrderWithItems() throws Exception {Starship starship = createData();findStarship(starship);}private Starship createData() {EntityManager entityManager = entityManagerFactory.createEntityManager();EntityTransaction transaction = entityManager.getTransaction();transaction.begin();Physics physics = physics().height(137.5D).length(642.5D).power("Wrap reactor").width(467.0D).build();Calendar launched = Calendar.getInstance();launched.set(2363, 9, 4);Starship starship = starship().registry("NCC-1701-D").physics(physics).launched(launched.getTime()).starshipClass(StarshipClassEnum.GALAXY).affiliation(AffiliationEnum.STARFLEET).build();Officer jeanLucPicard = officer().name("Jean-Luc Picard").rank(RankEnum.CAPTAIN).affiliation(AffiliationEnum.STARFLEET).homePlanet(PlanetEnum.EARTH).speciment(SpeciesEnum.HUMAN).build();starship.addOfficer(jeanLucPicard);Officer williamRiker = officer().name("William Riker").rank(RankEnum.COMMANDER).affiliation(AffiliationEnum.STARFLEET).homePlanet(PlanetEnum.EARTH).speciment(SpeciesEnum.HUMAN).build();starship.addOfficer(williamRiker);Officer data = officer().name("Data").rank(RankEnum.LIEUTENANT_COMMANDER).affiliation(AffiliationEnum.STARFLEET).homePlanet(PlanetEnum.OMICRON_THETA).speciment(SpeciesEnum.ANDROID).build();starship.addOfficer(data);Officer geordiLaForge = officer().name("Geordi La Forge").rank(RankEnum.LIEUTENANT).affiliation(AffiliationEnum.STARFLEET).homePlanet(PlanetEnum.EARTH).speciment(SpeciesEnum.HUMAN).build();starship.addOfficer(geordiLaForge);Officer worf = officer().name("Worf").rank(RankEnum.LIEUTENANT).affiliation(AffiliationEnum.STARFLEET).homePlanet(PlanetEnum.QONOS).speciment(SpeciesEnum.KLINGON).build();starship.addOfficer(worf);Officer beverlyCrusher = officer().name("Beverly Crusher").rank(RankEnum.COMMANDER).affiliation(AffiliationEnum.STARFLEET).homePlanet(PlanetEnum.EARTH).speciment(SpeciesEnum.HUMAN).build();starship.addOfficer(beverlyCrusher);Officer deannaTroi = officer().name("Deanna Troi").rank(RankEnum.COMMANDER).affiliation(AffiliationEnum.STARFLEET).homePlanet(PlanetEnum.BETAZED).speciment(SpeciesEnum.BETAZOID).build();starship.addOfficer(deannaTroi);entityManager.persist(starship);transaction.commit();entityManager.close();return starship;}private void findStarship(Starship starship) {EntityManager entityManager = this.entityManagerFactory.createEntityManager();EntityTransaction transaction = entityManager.getTransaction();transaction.begin();System.out.println("Before Find");Starship newStarship = entityManager.find(Starship.class, starship.getId());System.out.println("After Find Before Commit");transaction.commit();System.out.println("After commit");entityManager.close();}
}

現在我們已經創建了這個測試,我們可以運行它,并且我們將觀察Hibernate控制臺的輸出。

Hibernate: insert into Starship (affiliationEnum, launched, height, length, power, width, registry, starshipClassEnum, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)Before Find Starship By IdHibernate: select starship0_.id as id1_0_, starship0_.affiliationEnum as affiliat2_1_0_, starship0_.launched as launched1_0_, starship0_.height as height1_0_, starship0_.length as length1_0_, starship0_.power as power1_0_, starship0_.width as width1_0_, starship0_.registry as registry1_0_, starship0_.starshipClassEnum as starship9_1_0_ from Starship starship0_ where starship0_.id=?After Find Starship By Id and Before CommitHibernate: select officers0_.Starship_id as Starship1_1_2_, officers0_.officers_id as officers2_2_, officer1_.id as id0_0_, officer1_.affiliationEnum as affiliat2_0_0_, officer1_.homePlanet as homePlanet0_0_, officer1_.name as name0_0_, officer1_.rank as rank0_0_, officer1_.speciesEnum as speciesE6_0_0_, officer1_.starship_id as starship7_0_0_, starship2_.id as id1_1_, starship2_.affiliationEnum as affiliat2_1_1_, starship2_.launched as launched1_1_, starship2_.height as height1_1_, starship2_.length as length1_1_, starship2_.power as power1_1_, starship2_.width as width1_1_, starship2_.registry as registry1_1_, starship2_.starshipClassEnum as starship9_1_1_ from Starship_Officer officers0_ inner join Officer officer1_ on officers0_.officers_id=officer1_.id left outer join Starship starship2_ on officer1_.starship_id=starship2_.id where officers0_.Starship_id=?
Hibernate: delete from Starship_Officer where Starship_id=?
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)
Hibernate: insert into Starship_Officer (Starship_id, officers_id) values (?, ?)After commit

查看在第一次提交期間(持久對象)和在第二次事務提交期間(查找Starship )執行的查詢數。 在忽略序列生成器的總和中,我們可以計數22個inserts ,2個selects和1個delete ,這在我們僅創建8個對象和1個通過主鍵查找時很不錯。

此時,讓我們檢查為什么執行這些SQL查詢:

前八個插頁不可避免。 通過將數據插入數據庫需要它們。

接下來的七都需要插入,因為我們已經注釋getOfficers財產沒有的mappedBy屬性。 如果我們仔細查看Hibernate文檔,它會指出“在不描述任何物理映射的情況下,將使用具有連接表的單向一對多 ”。

下一組查詢甚至更陌生,第一個選擇語句是通過id查找Starship,但是我們已經創建的這些數據刪除和插入是什么?

在提交期間, Hibernate通過比較對象引用來驗證集合屬性是否臟。 當一個集合被標記為臟集合時, Hibernate需要重新創建整個集合,甚至包含相同的對象。 在本例中,當我們要招募軍官時,我們要返回一個不同的收集實例,具體來說是不可修改的列表,因此Hibernate認為軍官的收集是骯臟的。

由于使用了聯接表,因此應重新創建Starship_Officer表,刪除先前插入的元組并插入新的元組(盡管它們具有相同的值)。

讓我們嘗試解決此問題。 我們首先映射一個雙向的一對多關聯,并以多對一的一方為擁有方。

private List<Officer> officers = new ArrayList<Officer>();
@OneToMany(mappedBy="starship", cascade={CascadeType.ALL}) public  List<Officer> getOfficers() {return Collections.unmodifiableList(officers);}
protected void setOfficers(List<Officer> officers) {this.officers = officers;}
public void addOfficer(Officer officer) {this.officers.add(officer);}

現在,我們再次重新運行相同的測試,并再次檢查輸出。

Hibernate: insert into Starship (affiliationEnum, launched, height, length, power, width, registry, starshipClassEnum, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)Before Find Starship By IdHibernate: select starship0_.id as id1_0_, starship0_.affiliationEnum as affiliat2_1_0_, starship0_.launched as launched1_0_, starship0_.height as height1_0_, starship0_.length as length1_0_, starship0_.power as power1_0_, starship0_.width as width1_0_, starship0_.registry as registry1_0_, starship0_.starshipClassEnum as starship9_1_0_ from Starship starship0_ where starship0_.id=?After Find Starship By Id and Before CommitHibernate: select officers0_.starship_id as starship7_1_1_, officers0_.id as id1_, officers0_.id as id0_0_, officers0_.affiliationEnum as affiliat2_0_0_, officers0_.homePlanet as homePlanet0_0_, officers0_.name as name0_0_, officers0_.rank as rank0_0_, officers0_.speciesEnum as speciesE6_0_0_, officers0_.starship_id as starship7_0_0_ from Officer officers0_ where officers0_.starship_id=?After commit

盡管我們已將SQL語句的數量從25個減少到10個,但仍然有一個不必要的查詢,即第二個事務的commit部分中的查詢。 為什么如果默認情況下軍官是懶惰的( JPA規范),而我們又沒有讓軍官進行交易,那么Hibernate會在“軍官”表上執行選擇嗎? 由于與先前配置相同的原因,返回的集合具有不同的Java標識符,因此Hibernate將其標記為新實例化的集合,但是現在顯然不再需要連接表操作。 我們減少了查詢數量,但是仍然存在性能問題。 可能我們需要其他解決方案,而該解決方案不是最明顯的解決方案,我們不會返回Hibernate返回的集合對象,我們稍后可能會對此進行擴展,但是我們將更改批注的位置。

我們要做的是將映射位置從屬性方法更改為使用字段映射。 簡單來說,我們將所有注釋移至類屬性,而不是getter上

@Entity
public class Starship {@Id @GeneratedValue(strategy=GenerationType.SEQUENCE) private Long id;public Long getId() {return id;}protected void setId(Long id) {this.id = id;}@Temporal(TemporalType.DATE) private Date launched;public Date getLaunched() {return launched;}public void setLaunched(Date launched) {this.launched = launched;}...@OneToMany(mappedBy="starship", cascade={CascadeType.ALL}) private List<Officer> officers = new ArrayList<Officer>();public List<Officer> getOfficers() {return Collections.unmodifiableList(officers);}protected void setOfficers(List<Officer> officers) {this.officers = officers;}public void addOfficer(Officer officer) {officer.setStarship(this);this.officers.add(officer);}public Starship() {super();}public Starship(String registry) {setRegistry(registry);}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result+ ((registry == null) ? 0 : registry.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Starship other = (Starship) obj;if (registry == null) {if (other.registry != null)return false;} else if (!registry.equals(other.registry))return false;return true;} 
}
@Entity
public class Officer {@Id @GeneratedValue(strategy=GenerationType.SEQUENCE) private Long id;public Long getId() {return id;}protected void setId(Long id) {this.id = id;}@Column(unique=true, nullable=false) private String name;public String getName() {return this.name;}public void setName(String name) {this.name = name;}@Enumerated private SpeciesEnum speciesEnum;public SpeciesEnum getSpeciesEnum() {return speciesEnum;}public void setSpeciesEnum(SpeciesEnum speciesEnum) {this.speciesEnum = speciesEnum;}...@ManyToOne private Starship starship; public Starship getStarship() {return starship;}protected void setStarship(Starship starship) {this.starship = starship;}public Officer() {super();}public Officer(String name, RankEnum rank) {setName(name);setRank(rank);}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + ((name == null) ? 0 : name.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Officer other = (Officer) obj;if (name == null) {if (other.name != null)return false;} else if (!name.equals(other.name))return false;return true;}
}

最后,我們將再次運行測試,看看會發生什么:

Hibernate: insert into Starship (affiliationEnum, launched, height, length, power, width, registry, starshipClassEnum, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Officer (affiliationEnum, homePlanet, name, rank, speciesEnum, starship_id, id) values (?, ?, ?, ?, ?, ?, ?)Before Find
Hibernate: select starship0_.id as id1_0_, starship0_.affiliationEnum as affiliat2_1_0_, starship0_.launched as launched1_0_, starship0_.height as height1_0_, starship0_.length as length1_0_, starship0_.power as power1_0_, starship0_.width as width1_0_, starship0_.registry as registry1_0_, starship0_.starshipClassEnum as starship9_1_0_ from Starship starship0_ where starship0_.id=?After Find Before Commit
After commit

為什么使用屬性映射Hibernate在提交期間運行查詢并且不執行使用字段映射? 提交事務后,Hibernate執行刷新以使基礎持久性存儲與內存中保持的可持久狀態同步。 當使用屬性映射時,Hibernate調用getter / setter方法來同步數據,對于getOfficers方法,它將返回一個臟集合(由于進行了unmodifiableList調用)。 另一方面,當我們使用字段映射時, Hibernate直接獲取字段,因此收集不被認為是骯臟的,并且不需要重新創建。

但是我們還沒有完成,我想您想知道為什么我們還沒有從getter中刪除Collections.unmodifiableList,而是返回Hibernate集合? 是的,我同意您的意見,我們很快完成了工作,更改看起來像@ OneToMany(cascade = {CascadeType.ALL} )public List <Officer> getOfficers(){ 但是返回原始集合最終會導致封裝問題,實際上我們的封裝已損壞! 我們可以將任何所需的內容添加到可變列表中; 我們可以將不受控制的更改應用于對象的內部狀態。

使用unmodifiableList是避免破壞封裝的一種方法,但是我們當然可以對公共訪問和休眠訪問使用不同的訪問器,而不用調用Collections.unmodifiableList方法。

考慮到我們今天所看到的,我建議您使用始終字段注釋而不是屬性映射,我們將避免很多意外。

希望您發現這篇文章有用。

此示例的屏幕截圖:

下載代碼

參考: Hibernate性能提示: JCG合作伙伴的 臟回收效應 ? 在一個罐子統治他們所有博客的亞歷克斯·索托。


翻譯自: https://www.javacodegeeks.com/2012/03/hibernate-performance-tips-dirty.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/373396.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/373396.shtml
英文地址,請注明出處:http://en.pswp.cn/news/373396.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

java runtime 異常_Java中RuntimeException和Exception

在java的異常類體系中,Error和RuntimeException是非檢查型異常&#xff0c;其他的都是檢查型異常。所有方法都可以在不聲明throws的情況下拋出RuntimeException及其子類不可以在不聲明的情況下拋出非RuntimeException簡單的說&#xff0c;非RuntimeException必要自己寫catch塊處…

BZOJ3130: [Sdoi2013]費用流[最大流 實數二分]

3130: [Sdoi2013]費用流 Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 960 Solved: 505[Submit][Status][Discuss]Description Alice和Bob在圖論課程上學習了最大流和最小費用最大流的相關知識。 最大流問題&#xff1a;給定一張有向圖表示運輸網絡…

Linux Shell 003-變量

Linux Shell 003-變量 本節關鍵字&#xff1a;Linux、Shell、變量、全局變量、系統變量 相關指令&#xff1a;read、echo、unset、export 變量的含義 變量是用來臨時保存數據的&#xff0c;該數據是可以變化的數據。如果某個內容需要多次使用&#xff0c;并且在代碼中重復出現…

Java自動機實現

這篇文章將解決在Java中實現有限狀態機的問題。 如果您不知道什么是FSM或在什么地方可以使用FSM&#xff0c;您可能會熱衷于閱讀此 &#xff0c; 這個和這個 。 如果您發現自己在設計上使用FSM的情況&#xff0c;則可能已經開始為實現相同接口的每個狀態編寫類。 一個好的設計可…

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files這個文件找不到

在C:\Windows\Microsoft.NET\Framework64\v4.0.30319文件夾下面建立Temporary ASP.NET Files 文件夾&#xff08;Framework64 注意64&#xff0c;這個可能是我們用的64位系統&#xff0c;但是vs2010不分32位還是64位&#xff0c;所以在C:\Windows\Microsoft.NET\Framework\v4.0…

java電腦運行視頻演示_javaweb視頻第一天(二)

無論通過哪種方式得到的class類對象&#xff0c;是同一個。比較的是地址碼這里教會你&#xff1a;如何去使用class對象現在就知道這個&#xff1a;如何使用反射&#xff0c;并且說反射是實現了什么樣的功能。如何通過反射得到里面的相應字段&#xff0c;得到里面的相應函數等等…

模型驅動 ModelDriven

ModelDriven:模型驅動,對所有action的模型對象進行批處理. 我們在開發中&#xff0c; 在action中一般是用實體對象&#xff0c;然后給實體對象get&#xff0c;set方法。 RegAction{   User user ;   //get/set} 然后在jsp頁面中給action中的user屬性綁定值是通過如下方式 &…

本月風味– Neo4j和Heroku

Neo4j今年早些時候發起了一項挑戰&#xff0c;即“ 種子播云 ”&#xff0c;以使人們使用Neo4j附加組件在Heroku上創建模板或演示應用程序。 經過許多內部辯論之后&#xff0c;我決定進入&#xff0c;但由于缺乏想法而陷入絕望。 當我什么都沒做的時候&#xff0c;這個主意就出…

1 + 11 + 1111+ 11111+ ..... + 11111(2016個) 結果是幾位數

# -*- coding: utf-8 -*- """ Created on Mon Mar 21 20:38:06 2016author: yanjie """1 11 1111 11111 ..... 11111(2016個) 結果是幾位數 用什么數據結構 有幾個6 寫算法a []; m 0; six 0; for i in range(2016,0,-1):b (im) % 10;m (…

[回歸分析][10]--相關誤差的問題

[回歸分析][10]--相關誤差的問題這一篇文章還是來分析相關誤差的問題。 1.游程數 定義&#xff1a;游程數--殘差穿過x-軸的次數 用這個可以檢查如殘差有一塊在x軸上面&#xff0c;一塊在x軸下面的情形。 如上面這樣的殘差 下面構造兩個統計量&#xff1a; 其中 n…

Spring 3 MVC異常處理程序

我遇到的大多數Spring 3錯誤處理示例代碼似乎都提供了其用法的最簡單概述&#xff0c;但是&#xff0c;有人說&#xff0c;如何處理錯誤比正常代碼的工作方式更為重要。 前一天&#xff0c;當我在Spring&#xff08;2&#xff09;錯誤處理程序中遇到一個簡單的GOTCHA時&#xf…

java編譯找不到符號_javac編譯時找不到符號?

我是個新手&#xff0c;在linux使用java編程時&#xff0c;出現這個情況。我把要引的包放在classpath中&#xff0c;紅色部分&#xff1a;export CLASSPATH.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$HADOOP_HOME/hadoop-1.0.4.core.jar:${CLASSPATH}通過echo $CLASSP…

全備份、差異備份和增量備份概念詳述

全備份、差異備份和增量備份概念詳述 1、完全備份&#xff08;Full Backup&#xff09; 備份全部選中的文件夾&#xff0c;并不依賴文件的存檔屬性來確定備份那些文件。在備份過程中&#xff0c;任何現有的標記都被清除&#xff0c;每個文件都被標記為已備份。換言之&#xff0…

微信接入登錄功能access_token流程記錄

提示&#xff1a;只有認證過的訂閱號或者服務號才能獲取access_token。 1.app微信登錄第一步是&#xff0c;app調起來微信客戶端&#xff0c;通過app端的配置&#xff0c;引入一個微信類庫&#xff0c; 2.授權成功后&#xff0c;微信會返回你一個code。 將APP_ID替換成你在微信…

使用MVC模式制作游戲-教程和簡介

游戲開發中一種有用的體系結構模式是MVC&#xff08;模型視圖控制器&#xff09;模式。 它有助于分離輸入邏輯&#xff0c;游戲邏輯和UI&#xff08;渲染&#xff09;。 在任何游戲開發項目的早期階段&#xff0c;其實用性很快就會被注意到&#xff0c;因為它允許快速更改內容&…

boost

參考博客 http://www.cnblogs.com/lidabo/p/3805487.html http://www.cppblog.com/Robertxiao/archive/2013/01/06/197022.html http://www.cnblogs.com/finallyliuyu/archive/2013/05/23/3094246.html http://www.cnblogs.com/lidabo/p/3782193.html http://www.cnblogs.com/z…

moment格式換時間_不一樣的日期、時間轉換(moment.js)

無意中遇到了一種很奇怪的日期格式&#xff0c;從接口中返回的日期是這樣的&#xff0c;如 2018-02-06T11:59:2208:00 。然而這卻不是我們想要的&#xff0c;我們要的是這種&#xff0c;YYYY-MM-DD HH:mm:ss。那么這種是怎么轉換的呢&#xff1f;這時候就可以使用一款很好用的日…

并發模式:生產者和消費者

在我15年的職業生涯中&#xff0c;生產者和消費者的問題是我僅遇到過幾次。 在大多數編程情況下&#xff0c;我們正在做的事情是以同步方式執行功能&#xff0c;其中JVM或Web容器自行處理多線程的復雜性。 但是&#xff0c;在編寫某些需要的用例時。 上周&#xff0c;我遇到了一…

POJ 1006 - Biorhythms (中國剩余定理)

B - BiorhythmsTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1006Description 人生來就有三個生理周期&#xff0c;分別為體力、感情和智力周期&#xff0c;它們的周期長度為23天、28天和33天。每一個周期中…

子線程中更新UI線程的三個方法

1、通過handler方式&#xff0c;sendmessage。 多個類間傳遞比較麻煩&#xff0c;也懶的寫... 2、線程中通過runOnUiThread&#xff08;&#xff09; new Thread() { public void run() { //這兒是耗時操作&#xff0c;完成之后更新UI&#xff1b; runOnUiThread(new Runnab…