Привет! Меня зовут Диана, и я занимаюсь разработкой с 2013. Здесь пишу просто и понятно про джава бэк
🔥Тот самый курс по многопочке🔥
https://fillthegaps.ru/mt
Комплименты, вопросы, предложения: @utki_letyat
Post #642
8.86K
- 🔥 15
- 👍 5
JA @java_fillthegaps
Showing posts older than #643 · Back to latest
spring.task.scheduling.pool.size=5
public class HashSet implements Set {
HashMap map;
public HashSet() {
map = new HashMap<>();
}
...
}HashSet(int initialCapacity, float loadFactor, boolean dummy) {
map = new LinkedHashMap<>(initialCapacity, loadFactor);
}class LinkedHashSet implements Set {
private LinkedHashMap map;
public LinkedHashSet() {
this.map = new LinkedHashMap<>();
}
...
}LinkedHashMap<Integer, Integer> map = new LinkedHashMap<>();
map.put(1, 1);
map.put(2, 2);
int lastKey = map.sequencedKeySet().getLast(); // 2
LinkedHashMap<Integer, Integer> map = new LinkedHashMap<>(16, 0.8f, true);
map.put(1, 1);
map.put(2, 2);
map.get(1);
int lastKey = map.sequencedKeySet().getLast(); // 1
Map map = Collections.synchronizedMap(new LinkedHashMap(…))
Executors.newFixedThreadPool(int nThreads)
Executors.newSingleThreadExecutor()
Executors.newCachedThreadPool()
CREATE TABLE tweets (
id BIGINT ... PRIMARY KEY,
text VARCHAR(255) NOT NULL,
parent_id BIGINT REFERENCES tweets(id)
);
public Tweet saveTweet(Tweet tweet) {
// проверяем, что родитель существует
if (tweet.getParentId() != null) {
boolean parentExists = tweetRepository.existsById(tweet.getParentId());
if (!parentExists) {
throw new IllegalArgumentException("Parent not exists");
}
}
return tweetRepository.save(tweet);
}PostConstruct или ловят событие ApplicationReadyEvent. Но у таких вариантов есть существенный минус. PostConstruct, как отключить его в тестах? Можно добавить флажок, сделать подкласс и заменить его в тестовом конфиге, но это не всегда помогает и часто выглядит как костыль. @SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(MainApplication.class, args);
AccountService accService = ctx.getBean(AccountService.class);
accService.loadDictionary();
}
}
SpringBootTest метод main не запускается. Соответственно, код внутри не выполняется. Нет костылей вокруг PostConstruct, всё чисто и красиво❤️🩹@SpringBootTest(useMainMethod = SpringBootTest.UseMainMethod.ALWAYS)
class Employee extends Person {
private static int verifyAge(int value) {
if (age < 18)
throw new IllegalArgumentException(...);
return value;
}
Employee(int age) {
super(verifyAge(age));
}
}class Employee extends Person {
Employee(int age) {
if (age < 18)
throw new IllegalArgumentException(...);
super(age);
}
}public Person {
// prologue
super();
// epilogue
}Employee(int age, String officeID) {
this.officeID = officeID;
super(age);
}