java - AtomicInteger Class Inconsistency -
i using atomicinteger class increment value of customerid , productid. dont have database using serialization store state of application , command based application. everytime add customer or product costructor calls idgenerateor class has atomicinteger create id. there inconsistency, somtimes increment id , not, tell me whats wrong.
public final class idgenerator implements serializable { private static atomicinteger nextid = new atomicinteger(); public static int newid() { return nextid.incrementandget(); } } public customer (string name, string email, string phone, address address) { this.name = name; this.email = email; this.phone = phone.replaceall("[\\s\\-()]", ""); // drop non-digit characters this.address = address; this.id = idgenerator.newid(); this.facebook=""; this.twitter=""; this.deliveryinstructions=""; }
Comments
Post a Comment