Created
July 3, 2020 19:39
-
-
Save bgocean/c422845ac47e71feb491c4983950559a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task17.task1719; | |
import java.util.HashMap; | |
import java.util.Map; | |
/* | |
ApplicationContext | |
ApplicationContext будет доступен множеству нитей. | |
Сделать так, чтобы данные не терялись: подумай, какое ключевое слово необходимо поставить и где. | |
Требования: | |
1. Класс ApplicationContext должен быть абстрактным. | |
2. Класс ApplicationContext должен содержать private поле container типа Map<String, GenericsBean>. | |
3. В getByName(String name), если необходимо, используй synchronized. | |
4. В removeByName(String name), если необходимо, используй synchronized. | |
*/ | |
public abstract class ApplicationContext<GenericsBean extends Bean> { | |
private Map<String, GenericsBean> container = new HashMap<String, GenericsBean>(); | |
// Map<Name, some class that implements the Bean interface> | |
protected ApplicationContext() { | |
parseAllClassesAndInterfaces(); | |
} | |
public synchronized GenericsBean getByName(String name) { | |
return container.get(name); | |
} | |
public synchronized GenericsBean removeByName(String name) { | |
return container.remove(name); | |
} | |
protected abstract void parseAllClassesAndInterfaces(); | |
public static void main(String[] args) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task17.task1719; | |
public interface Bean { // это интерфейс-маркер | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment