hibernate脏数据_Hibernate性能提示:脏收集效果

hibernate脏数据

在使用Hibernate作为ORM开发服务器和嵌入式应用程序8年后,我全力以赴地寻求提高Hibernate性能的解决方案,阅读博客和参加会议,我决定与您分享在这些年中获得的知识。

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

去年,我以Devoxx的身份参加了演讲,但是我也参加了关于Hibernate反模式的 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查询:

前8个插入是不可避免的。 通过将数据插入数据库需要它们。

接下来的七都需要插入,因为我们已经注释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是避免破坏封装的一种方法,但是我们当然可以对公共访问和Hibernate访问使用不同的访问器,而不用调用Collections.unmodifiableList方法。

考虑到我们今天所看到的,我建议您使用始终字段注释而不是属性映射,我们将避免很多意外。

希望您发现这篇文章有用。

此示例的屏幕截图:

下载代码

参考: Hibernate性能提示: JCG合作伙伴的 脏回收效应   在一个罐子统治他们所有博客的亚历克斯·索托。


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

hibernate脏数据

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/356839.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

有关struts2中用到 js 总结

1.js中取Struts2中的栈里的值 var current "${currentPage}"; 2.js 如何提交执行提交url连接 &#xff0c;以及 Struts中的url如何如何写 var current "${currentPage}"; location.href"showSeparatePageGoods.action?currentPage"current&q…

java合并两个有序链表_JS实现的合并两个有序链表算法示例

本文实例讲述了JS实现的合并两个有序链表算法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。示例&#xff1a;输入&#xff1a;1->2->4, 1->3->4输出&…

外墙设计模式示例

本文是我们名为“ Java设计模式 ”的学院课程的一部分。 在本课程中&#xff0c;您将深入研究大量的设计模式&#xff0c;并了解如何在Java中实现和利用它们。 您将了解模式如此重要的原因&#xff0c;并了解何时以及如何应用模式中的每一个。 在这里查看 &#xff01; 目录 …

8.25小结

1.导出csv文件 后台导出&#xff1a;CSVUtils工具类&#xff1a; /*** * CSV文件导出工具类* * author* reviewer*/ public class CSVUtils {public static File createCSVFile(List<Object> head, List<List<Object>>dataList, String outPutPath, String f…

java 监控 native 内存_JVM NativeMemoryTracking 分析堆外内存泄露

Native Memory Tracking (NMT) 是Hotspot VM用来分析VM内部内存使用情况的一个功能。我们可以利用jcmd(jdk自带)这个工具来访问NMT的数据。NMT介绍工欲善其事必先利其器&#xff0c;我们先把相关需要的配置和工具介绍清楚&#xff0c;再通过例子来看看具体如何使用NMT。打开NMT…

Charles 从入门到精通

目录与版权 转载请保留顶部的 Charles 中国特惠内容&#xff0c;本文的内容主要包括&#xff1a; Charles 的简介如何安装 Charles将 Charles 设置成系统代理Charles 主界面介绍过滤网络请求截取 iPhone 上的网络封包截取 Https 通讯信息模拟慢速网络修改网络请求内容给服务器做…

javafx11 最佳实践_JavaFX移动应用程序最佳实践,第1部分

javafx11 最佳实践到现在为止&#xff0c;所有对JavaFX感兴趣的人都会知道&#xff0c;JavaFX Mobile发行了不久 前。 可以肯定的是&#xff0c;这真是令人难以置信。 我感到非常筋疲力尽&#xff0c;在发行期间我什至没有精力去写博客…… 但是到目前为止&#xff0c;我感到很…

java 批量验证_正则表达式批量验证函数

正则表达式批量验证函数function checkData(){//判断数据的正确性var idSpans new Array();idSpans[0] new Array("item_4","^[\\s\\S]{1,16}$","productName","商机名称应在1-16字以内","",true); idSpans[1] new Array(…

css3制作炫酷导航栏效果 转

今天主要利用hover选择器。鼠标滑过查看效果。 一。普通导航栏 HomeContentServiceTeamContact对于这种普通的导航栏&#xff0c;只是鼠标滑过的时候颜色会变&#xff0c;所以思路变得很简单。 &#xff08;1&#xff09;使用ul标签布局 &#xff08;2&#xff09;鼠标经过事件…

桥梁设计模式示例

本文是我们名为“ Java设计模式 ”的学院课程的一部分。 在本课程中&#xff0c;您将深入研究大量的设计模式&#xff0c;并了解如何在Java中实现和利用它们。 您将了解模式如此重要的原因&#xff0c;并了解何时以及如何应用模式中的每一个。 在这里查看 &#xff01; 目录 …

java计算面积的方法_JAVA多态计算面积main函数调用方法

public static void main(String[] args) {Shape shape;Scanner input new Scanner(System.in);System.out.println("请选择图形(1、圆形 2、矩形 3、三角形)");int a input.nextInt();if(a 1){System.out.println("请输入圆形的边长&#xff1a;");dou…

C# 5.0新加特性

1. 异步编程 在.Net 4.5中&#xff0c;通过async和await两个关键字&#xff0c;引入了一种新的基于任务的异步编程模型&#xff08;TAP&#xff09;。在这种方式下&#xff0c;可以通过类似同步方式编写异步代码&#xff0c;极大简化了异步编程模型。如下式一个简单的实例&…

java 生成缩略图类_JAVA生成【缩略图】方法

/*** 创建缩略图片** param orgpath* param filename* return* description: 描述*///此方法对于ssh项目并且针对 上传功能时&#xff0c;非常有用public static Boolean createAbbreviateImg(String orgpath, String filename) {Boolean flag true;String filetype orgpath.…

简单的遮罩层加登录窗效果

<!DOCTYPE html> <html> <head> <meta charset"utf-8" /> <title>遮罩层加登录窗</title> <style type"text/css"> #wrap{width: 60px;height: 30px; position: absolute; text-align: center; line-height: 30…

java上机面试题 039_深入 Java 虚拟机之面试总结篇

在学习 JVM 相关知识&#xff0c;怎么让自己有动力看下去&#xff0c;且有思考性呢&#xff1f;笔者认为&#xff0c;开头用一些常用的面试题&#xff0c;来引入读者的兴趣比较好&#xff0c;这样才会有看下去的动力。所以&#xff0c;该篇文章会以面试总结的方式&#xff0c;希…

可重试的操作

在我从事的每个项目中&#xff0c;总是需要某些功能&#xff1a;重试操作。 通常&#xff0c;它是关于通过网络的呼叫&#xff0c;该呼叫可能一次失败&#xff0c;但随后会成功。 它可能涉及许多其他内容&#xff0c;主要包括与另一个系统的通信&#xff08;无论是否通过网络&a…

常用加密算法的Java实现(一) ——单向加密算法MD5和SHA

1、Java的安全体系架构 1.1 Java的安全体系架构介绍 Java中为安全框架提供类和接口。JDK 安全 API 是 Java 编程语言的核心 API&#xff0c;位于 java.security 包&#xff08;及其子包&#xff09;&#xff0c;以及sun.securityAPI包&#xff08;及其子包&#xff0…

java 限制并发数_限制并发请求数aiohttp

您的限制设置正常 . 你在调试时弄错了 .正如Mikhail Gerasimov在the comment指出的那样&#xff0c;你将 print() 调用放在错误的位置 - 它必须在 session.get() 上下文中 .为了确保限制得到尊重&#xff0c;我针对简单的日志记录服务器测试了您的代码 - 测试显示服务器接收到您…

redis aof持久化遇到的Can't open the append-only file Permissi

redis aof持久化生成的默认文件appendonly.aof 默认只读属性。 redis重启启动加载数据的时候会提示 &#xff1a;Cant open the append-only file: Permission denied 解决办法就是去掉appendonly.aof的只读属性。 解决办法就是redis.conf里面配置的dir /var/redis/6379以及里面…

jar包不用java命令_使不能运行的JAR文件可以使用java -jar运行

"); System.exit(0); }请注重参数列表是如何被解释的&#xff0c;因为这对于后面的代码是非常重要的。参数的顺序和内容并不是硬性设置的&#xff0c;但是假如你改变它们也要记得适当的修改其他的代码。访问JAR和它的manifest文件首先我们必须创建一些知道JAR和manifest文…