Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In
Continue with Google
Continue with Facebook
or use


Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here
Continue with Google
Continue with Facebook
or use


Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.


Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Continue with Google
Continue with Facebook
or use


Forgot Password?

Need An Account, Sign Up Here

Sorry, you do not have a permission to ask a question, You must login to ask question.

Continue with Google
Continue with Facebook
or use


Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Stack Ask

Stack Ask Logo Stack Ask Logo

Stack Ask Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us

monkey

Enlightened
Ask monkey
1 Follower
88 Questions
Home/ monkey/Best Answers
  • About
  • Questions
  • Answers
  • Best Answers
  • Asked Questions
  • Followed Questions
  • Favorite Questions
  • Posts
  • Comments
  • Followers Questions
  • Followers Answers
  • Followers Posts
  • Followers Comments
  1. Asked: May 25, 2022In: SQL

    Xử lý java khi saveall vào database 1 danh sách có nhiều dữ liệu

    monkey Enlightened
    Added an answer on May 25, 2022 at 4:52 am

    1. Em có thể lưu dữ liệu tạm ở Local và sau đó save dần dần: tuy nhiên cách này đòi hỏi em phải cứng tay 1 chút trong xử lý I/O cụ thể là làm việc với File, cũng có rủi ro là cái server local có thể bị hết disk. 2. Em có thể sử dụng kafka, em cứ push dữ liệu và kafka, sau đó ở ở đầu consumer, em sẽRead more

    1. Em có thể lưu dữ liệu tạm ở Local và sau đó save dần dần: tuy nhiên cách này đòi hỏi em phải cứng tay 1 chút trong xử lý I/O cụ thể là làm việc với File, cũng có rủi ro là cái server local có thể bị hết disk.
    2. Em có thể sử dụng kafka, em cứ push dữ liệu và kafka, sau đó ở ở đầu consumer, em sẽ lấy ra dần dần và save vào db: cách này thì đơn giản nhưng lại phát sinh thêm chi phí hạ tầng.

    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Asked: May 6, 2022In: Spring

    Nhiều instance service websocket ?

    monkey Enlightened
    Added an answer on May 6, 2022 at 2:40 am

    Hiện tại anh thấy có 1 giải pháp hay được dùng đó là em sẽ dùng kafka hoặc rabbitMQ hoặc activeMQ hoặc redis để broadcast message đến tất cả các server khi có tin nhắn đến, user kết nối đến server nào thì sẽ nhận được message ở server đó, cách này có vẻ là hiệu năng sẽ tương đối cao.

    Hiện tại anh thấy có 1 giải pháp hay được dùng đó là em sẽ dùng kafka hoặc rabbitMQ hoặc activeMQ hoặc redis để broadcast message đến tất cả các server khi có tin nhắn đến, user kết nối đến server nào thì sẽ nhận được message ở server đó, cách này có vẻ là hiệu năng sẽ tương đối cao.

    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. Asked: April 19, 2022In: Java

    Hỏi về queue ?

    monkey Enlightened
    Added an answer on April 19, 2022 at 4:47 am
    This answer was edited.

    Với kafka em có thể set props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 1);, so đó poll đủ số lượng em cần thì thôi em ạ. Ví dụ: List buffer = new ArrayList(); while (true) { final ConsumerRecords consumerRecords = consumer.poll(1000); if (consumerRecords.count() > 0) { buffer.add(rs.iterator()Read more

    Với kafka em có thể set props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 1);, so đó poll đủ số lượng em cần thì thôi em ạ. Ví dụ:

    List buffer = new ArrayList();
    while (true) {
        final ConsumerRecords consumerRecords =
                consumer.poll(1000);
    
        if (consumerRecords.count() > 0) {
            buffer.add(rs.iterator().next());
        }
    
        consumer.commitAsync();
        if (buffer.size() >= so luong phan tu can lay) {
            break;
        }
    }
    
    consume buffers
    buffers.clear();
    
    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. Asked: December 21, 2021In: Programming

    Tạo rồi xóa hay cập nhật, cái nào sẽ tốn resource hơn ?

    monkey Enlightened
    Added an answer on December 22, 2021 at 3:28 am

    Cái này thì nên tuỳ theo dự án và tính chất của data em ạ: 1. Đối với những dữ án mà em cam kết với người dùng là sẽ toàn bộ dữ liệu của họ khi họ yêu cầu thì em sẽ phải xoá, nếu em cam kết là xoá nhưng em chỉ cập nhật active = false thì việc này lộ ra thì công ty em sẽ gặp vấn đề rất rất nghiêm trọRead more

    Cái này thì nên tuỳ theo dự án và tính chất của data em ạ:

    1. Đối với những dữ án mà em cam kết với người dùng là sẽ toàn bộ dữ liệu của họ khi họ yêu cầu thì em sẽ phải xoá, nếu em cam kết là xoá nhưng em chỉ cập nhật active = false thì việc này lộ ra thì công ty em sẽ gặp vấn đề rất rất nghiêm trọng, đối với những công ty ở thị trường Nhật chẳng hạn có thể bị phá sản ngay lập tức.

    2. Trong trường hợp em chỉ cam kết là lưu trữ thông tin người dùng thì.

    2.1 Đối với các data quan trọng như thông tin người dùng, lịch sử giao dịch thì nên giữ lại (active = false) và sau đó move sang 1 database chuyên backup để phục vụ cho các nghiệp vụ tra cứu, đối soát hay các hệ thống bigdata và AI sau này.

    2.2. Đối với các data không quan trọng như session token, thì khi hết hạn thì có thể xoá đi được em ạ, để lại cũng chẳng để làm gì.

    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  5. Asked: December 10, 2021In: Spring

    Làm sao để cấu hình tới 2 database trong 1 project spring boot?

    monkey Enlightened
    Added an answer on December 10, 2021 at 6:59 am
    This answer was edited.

    Khi sử dụng sẽ kiểu thế này: import javax.sql.DataSource; @Configuration @EnableConfigurationProperties(HibernateProperties.class) @ImportAutoConfiguration(RepositoryPropertiesConfig.class) public class EzyJpaConfig { @Autowired private ApplicationContext appContext; public static final String EXAMPRead more

    Khi sử dụng sẽ kiểu thế này:

    import javax.sql.DataSource;
    
    @Configuration
    @EnableConfigurationProperties(HibernateProperties.class)
    @ImportAutoConfiguration(RepositoryPropertiesConfig.class)
    public class EzyJpaConfig {
    
        @Autowired
        private ApplicationContext appContext;
    
        public static final String EXAMPLE1 = "example1";
        public static final String EXAMPLE2 = "example2";
    
        @Bean
        public EzyDataSourceFactory repositoryDataSourceFactory(RepositoryProperties properties) {
            return new EzyDataSourceFactory(
                properties.getDataSources(),
                appContext.getEnvironment(),
                "spring.datasource.hikari"
            );
        }
    
        @Bean
        public EzyJpaRepositoryFactory repositoryJpaRepositoryFactory(
            EzyJpaTransactionManagerFactory repositoryJpaTransactionManagerFactory
        ) {
            return new EzyJpaRepositoryFactory(repositoryJpaTransactionManagerFactory);
        }
    
        @Bean
        public EzyEntityManagerFactoryFactory repositoryEntityManagerFactoryFactory(
            EzyDataSourceFactory repositoryDataSourceFactory,
            HibernateProperties hibernateProperties
        ) {
            return new EzyEntityManagerFactoryFactory(
                repositoryDataSourceFactory,
                hibernateProperties,
                "com.example.ezy.web.entity"
            );
        }
    
        @Bean
        public EzyJpaTransactionManagerFactory repositoryJpaTransactionManagerFactory(
            EzyEntityManagerFactoryFactory repositoryEntityManagerFactoryFactory
        ) {
            return new EzyJpaTransactionManagerFactory(repositoryEntityManagerFactoryFactory);
        }
    
        // ==================== example1 ==========
        @Bean
        public DataSource example1DataSource(EzyDataSourceFactory repositoryDataSourceFactory) {
            return repositoryDataSourceFactory.createDataSource(EXAMPLE1);
        }
    
        @Bean
        public EntityManagerFactory example1EntityManagerFactory(
            DataSource example1DataSource,
            EzyEntityManagerFactoryFactory repositoryEntityManagerFactoryFactory
        ) {
            return repositoryEntityManagerFactoryFactory.createEntityManagerFactory(
                EXAMPLE1,
                example1DataSource
            );
        }
    
        @Bean
        public JpaTransactionManager example1TransactionManager(
            EntityManagerFactory example1EntityManagerFactory,
            EzyJpaTransactionManagerFactory repositoryEntityManagerFactoryFactory
        ) {
            return repositoryEntityManagerFactoryFactory.createJpaTransactionManager(
                EXAMPLE1,
                example1EntityManagerFactory
            );
        }
    
        // ==================== example2 ==========
        @Bean
        public DataSource example2DataSource(EzyDataSourceFactory repositoryDataSourceFactory) {
            return repositoryDataSourceFactory.createDataSource(EXAMPLE2);
        }
    
        @Bean
        public EntityManagerFactory example2EntityManagerFactory(
            DataSource example2DataSource,
            EzyEntityManagerFactoryFactory repositoryEntityManagerFactoryFactory
        ) {
            return repositoryEntityManagerFactoryFactory.createEntityManagerFactory(
                EXAMPLE2,
                example2DataSource
            );
        }
    
        @Bean
        public JpaTransactionManager example2TransactionManager(
            EntityManagerFactory example2EntityManagerFactory,
            EzyJpaTransactionManagerFactory repositoryEntityManagerFactoryFactory
        ) {
            return repositoryEntityManagerFactoryFactory.createJpaTransactionManager(
                EXAMPLE2,
                example2EntityManagerFactory
            );
        }
    
        // ================= config ===========
    
        @Getter
        @ConstructorBinding
        @AllArgsConstructor
        @ConfigurationProperties(prefix = "jpa")
        public static class RepositoryProperties {
            private final Map dataSources;
        }
    
        @Configuration
        @EnableConfigurationProperties(RepositoryProperties.class)
        @ConditionalOnMissingBean(RepositoryProperties.class)
        public static class RepositoryPropertiesConfig {
        }
    }
    
    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  6. Asked: September 24, 2021In: Programming

    Cách hòa nhập nhanh khi tham gia dự án có code-base lớn

    monkey Enlightened
    Added an answer on September 24, 2021 at 6:32 am

    May quá anh cũng đang làm trong dự án to đùng đùng nên có thể chia sẻ được cho em: Đầu tiên chắc chắn là em sẽ được training về nghiệp vụ, overview, tech stack của dự án rồi Sau đó bọn anh bao giờ cũng có 1 task gọi là bootcamp, task này thường kéo dài khoảng 2 đến 3 tháng, em sẽ tìm 1 phần việc nàoRead more

    May quá anh cũng đang làm trong dự án to đùng đùng nên có thể chia sẻ được cho em:

    1. Đầu tiên chắc chắn là em sẽ được training về nghiệp vụ, overview, tech stack của dự án rồi
    2. Sau đó bọn anh bao giờ cũng có 1 task gọi là bootcamp, task này thường kéo dài khoảng 2 đến 3 tháng, em sẽ tìm 1 phần việc nào đó em cho là em có thể làm được vào thực hiện nó, trong quá trình này thì em nên tự chủ động tìm kiếm các thông tin và tổng hợp nó thành 1 wiki, không hiểu ở đâu thì em hỏi luôn
    3. Mới vào dự án thì nên đặt một mục tiêu nhỏ là hiểu 1 số chức năng mình đã quen thuộc, làm một số task kiểu fix bug hay làm chức năng mới để quen với code style và quy trình làm việc của team, vì dự án của em đã có sẵn rồi nên phải 1 2 năm em mới nắm được hết nên cứ bình tĩnh mà tận hưởng, đặc biệt đừng cố đập đi xây lại nhé, 😀

    Q1: Khi code-base quá lớn thì chúng ta nên bắt đầu từ việc tự vẽ lại system architecture của dự án, module diagram của dự án, dùng sản phẩm, vẽ lại một số luồng quan trọng

    Q2: Nếu hỏi và yêu cầu trợ giúp thì nên tạo wiki, hoặc nêu rõ nội dung mình cần hỏi là gì. Không biết bên em thế nào, chứ bên anh rất nice, mọi người cứ hỏi thôi, không rõ thì hỏi lại cũng không cần quan trọng lắm, nhưng để em nhận được câu trả lời nhanh nhất thì tốt nhất em nên đặt một câu hỏi với đầy đủ nội dung kiểu: tôi đang đọc/làm chức năng này, tôi đã làm thế này, hiện tại tôi đang gặp vấn đề ở chỗ này, các bạn giúp tôi với, kiểu vậy.

    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  7. Asked: September 1, 2021In: Anything

    Xóa 1 file trong toàn bộ commit của tất cả các branch

    monkey Enlightened
    Added an answer on September 1, 2021 at 8:52 am

    Chỉ có 1 cách duy nhất đó là: 1. em dừng code lại 2. backup code ra 1 folder khác 3. trở về điểm commit mà chưa add file đó vào bằng lệnh git reset --hard mã_commit-của_em 4. copy các file khác vào ngoại trừ file 400MB đó 5. commit và git push tên_branch -f 6. Tiếp tục code Rất tiếc cho em, anh cũngRead more

    Chỉ có 1 cách duy nhất đó là:

    1. em dừng code lại
    2. backup code ra 1 folder khác
    3. trở về điểm commit mà chưa add file đó vào bằng lệnh git reset --hard mã_commit-của_em
    4. copy các file khác vào ngoại trừ file 400MB đó
    5. commit và git push tên_branch -f
    6. Tiếp tục code

    Rất tiếc cho em, anh cũng đã từng bị thế này em ạ, 😀

    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  8. Asked: August 5, 2021In: Java

    Volatile boolean khác gì AtomicBoolean

    monkey Enlightened
    Added an answer on August 5, 2021 at 9:56 am
    This answer was edited.

    1. Volatile: là một dạng biến thông báo, nghĩa là nó được dùng để các thread thông báo cho nhau rằng biến có sự thay đổi giá trị, tuy nhiên nó không đảm bảo được là giá trị của biến sẽ được đồng bộ Ví dụ thông báo: public class VolatileExample { private volatile boolean active; public void prepare()Read more

    1. Volatile: là một dạng biến thông báo, nghĩa là nó được dùng để các thread thông báo cho nhau rằng biến có sự thay đổi giá trị, tuy nhiên nó không đảm bảo được là giá trị của biến sẽ được đồng bộ

    Ví dụ thông báo:

    public class VolatileExample {
    
        private volatile boolean active;
    
        public void prepare() throws InterruptedException {
            new Thread(() -> {
                System.out.println("application preparing ...");
                sleep(3);
                active = true;
            })
            .start();
        }
    
        public void start() throws Exception {
            new Thread(() -> {
                while(!active);
                System.out.println("application started");
            })
            .start();
        }
    
        private static void sleep(int second) {
            try {
                Thread.sleep(second * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    
        public static void main(String[] args) throws Exception {
            VolatileExample example = new VolatileExample();
            example.prepare();
            example.start();
            sleep(10);
        }
    }
    

    Nếu bạn bỏ từ khoá volatile thì hàm System.out.println("application started"); sẽ không bao giờ được in ra

    Ví dụ không đảm bảo đồng bộ giá trị:

    public class VolatileIntExample {
    
        private volatile int count;
        private final Map map = new ConcurrentHashMap();
    
        public void start() {
            Thread[] threads = new Thread[10];
            for (int i = 0 ; i < threads.length ; ++i) {
                threads[i] = new Thread(() ->
                    while(count <= 1000000) {
                        ++ count;
                        map.put(Integer.valueOf(count), Integer.valueOf(count));
                    }
                });
            }
            for (int i = 0 ; i < threads.length ; ++i) {
                threads[i].start();
            }
        }
    
        public static void main(String[] args) throws Exception {
            VolatileIntExample example = new VolatileIntExample();
            example.start();
            Thread.sleep(3000);
            System.out.println(example.map.size());
        }
    }
    

    nó sẽ in ra ngẫu nhiên, có thể là 979638

    2. AtomicBoolean: vừa có khả năng thông báo vừa đảm bảo giá trị sẽ được đồng bộ, vì bên trong nó sử dụng private volatile int value;, nên trong ví dụ trên, bạn cũng có thể sử dụng thế này:

    Ví dụ thông báo:

    public class AtomicExample {
    
        private AtomicBoolean active = new AtomicBoolean(false);
    
        public void prepare() throws InterruptedException {
            new Thread(() -> {
                System.out.println("application preparing ...");
                sleep(3);
                active.set(true);
            })
            .start();
        }
    
        public void start() throws Exception {
            new Thread(() -> {
                while(!active.get());
                System.out.println("application started");
            })
            .start();
        }
    
        private static void sleep(int second) {
            try {
                Thread.sleep(second * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    
        public static void main(String[] args) throws Exception {
            AtomicExample example = new AtomicExample();
            example.prepare();
            example.start();
            sleep(10);
        }
    }
    

    Ví dụ đông bộ dữ liệu:

    public class AtomicIntExample {
    
        private AtomicInteger count = new AtomicInteger(0);
        private final Map map = new ConcurrentHashMap();
    
        public void start() {
            Thread[] threads = new Thread[10];
            for (int i = 0 ; i < threads.length ; ++i) {
                threads[i] = new Thread(() -> {
                    int value;
                    while((value = count.incrementAndGet()) <= 1000000) {
                        map.put(Integer.valueOf(value), Integer.valueOf(value));
                    }
                });
            }
            for (int i = 0 ; i < threads.length ; ++i) {
                threads[i].start();
            }
        }
    
        public static void main(String[] args) throws Exception {
            AtomicIntExample example = new AtomicIntExample();
            example.start();
            Thread.sleep(3000);
            System.out.println(example.map.size());
        }
    }
    

    nó sẽ in ra 1000000

    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  9. Asked: July 30, 2021In: EzyFox Server

    Cách tạo mock ScheduledExecutorService cho EzyAppContext khi test

    monkey Enlightened
    Added an answer on July 30, 2021 at 6:59 am
    This answer was edited.

    em khởi tạo như vậy là đúng rồi em ạ em mock tiếp thế này: ScheduledExecutorService executorService = mock(ScheduledExecutorService.class); when(context.get(ScheduledExecutorService.class)).thenReturn(executorService); em nhé

    em khởi tạo như vậy là đúng rồi em ạ em mock tiếp thế này:

    ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
    when(context.get(ScheduledExecutorService.class)).thenReturn(executorService);
    

    em nhé

    See less
    • 1
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 554
  • Answers 1k
  • Best Answers 63
  • Users 291
  • Popular
  • Answers
  • monkey

    [Deep Learning] Làm thế nào để xác định được cái ...

    • 16 Answers
  • Tú Trần Anh

    [Ezyfox Server] Unity game client không gửi được command khi ...

    • 12 Answers
  • Thưởng Đặng Văn

    Multiple tenant multiple database .net core

    • 10 Answers
  • monkey
    monkey added an answer 1. Em có thể lưu dữ liệu tạm ở Local… May 25, 2022 at 4:52 am
  • Hoàng Kiếm
    Hoàng Kiếm added an answer Huy ơi bạn đã thử login bằng command, mysql -u… May 21, 2022 at 5:42 am
  • tvd12
    tvd12 added an answer public class EzyEventLoopGroup { private final EzyRoundRobin eventLoops; private final… May 19, 2022 at 2:20 pm

Top Members

tvd12

tvd12

  • 63 Questions
  • 1k Points
Enlightened
monkey

monkey

  • 88 Questions
  • 588 Points
Enlightened
Nguyễn Thái Sơn

Nguyễn Thái Sơn

  • 140 Questions
  • 220 Points
Professional

Trending Tags

.net core abstract class analytics android ansible anti-flooding apache poi api async asyncawait atomicboolean backend backend nestjs bash script batch bean big project binding bitcoin blockchain blog british buffered build bundle c# cache caching callback career career path cast centos chat cloud cloud reliability commit company content-disposition contract cors cosmos css database datasource datastructure decentralized exchange deep learning design-pattern devops dex distraction programing docker download draw.io du học dữ liệu lớn eclip editor employee english erc20 erc721 eth ethereum ethereum login extensions exyfox ezyfox ezyfox-boot ezyfox-server ezyfoxserver ezyhttp facebook fe flutter freetank french front-end frontend fullstack fulltextsearch future game game-box game-room game-server get git go golang google grapql grpc guide hazelcast hibernate hibernateconfig html http https indexing intellij interface interview io ipfs isolate issue it java javacore java core javascript java spring javaw java web job jpa js json jsp & servlet jvm jwt kafka keep promise kerberos keycloak kotlin language languague library load-balancing log log4j log4j-core login lưu trữ machine learning macos math maven merge messaging metamask microservice model msgpack multiple tenant multithread multithreading mysql n naming naming convention netcore netty nft nft game nio nodejs non-blocking io opensource optimize orm pagination pancakeswap panic pgpool phỏng vấn pointer postgresql pre programming promise push message android python python unicode question queue rabbitmq reactive reactjs reactjs download recyclerview redis request resource rest roadmap ropssten ropsten rust rxjava schedule search security server shift jis singleton sjis slack smart contract socket soft delete sosanh spring spring-boot-test spring-jpa spring aop spring boot springboot spring data jpa spring redis spring security springsecurity sql sql server sse stackask storage stream structure trong spring boot system environment variables thread threadjava thymeleaf totp tracking location unit test unity upload file vector view volatile vue vue cli web3 web3 client webpack websocket windows 11 winforms work zookeeper

Footer

Stack Ask

Stack Ask is where Developers Ask & Answers. It will help you resolve any questions and connect you with other people.

About Us

  • Meet The Team
  • About Us
  • Contact Us

Legal Stuff

  • Terms of Service
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2021 Stack Ask. All Rights Reserved
Powered by youngmonkeys.org