I need help making sure my code is thread safe

So I am trying to use SwingWorkers in my application (written in Java) where I collect some data from an API and display it in the app’s GUI. Please keep in mind that I am very unsure when it comes to threads, it’s a concept I struggle to grasp and understand.

I will provide the method for which the thread is being run, I’m not sure what else I need to provide but do let me know if there’s more that needs to be shown in order for me to get help.

    private void initialThread() {
        dataUpdateTimer = new Timer(60 * 60 * 1000, new ActionListener() { // Update every hour
            
            @Override
            public void actionPerformed(ActionEvent e) {
                rg.getLoadingMsg(); // Display the JOptionPane message
                if (cachedChannelData != null) { //If the cached data is not null
                    cachedChannelData.clear(); //Clear the cached data to make new cache
                }
                rg.clearChannelTable(); //Clear the table displaying the channels (GUI)
                rg.clearGui(); //Clear the rest of the GUI
                SwingWorker<Void, Map<String, Map<String, programClass>>> sw = new SwingWorker<Void, Map<String, Map<String, programClass>>>() {
                    @Override
                    protected Void doInBackground() throws Exception {
                        cachedChannelData = cm.loadChannels(); //Get the channels (data retrieved from API)
                        publish(cachedChannelData); //Send the data that's been collected
                        return null; // Ensure doInBackground returns null as specified by its return type
                    }
    
                    @Override
                    protected void process(List<Map<String, Map<String, programClass>>> chunks) {

                        Map<String, Map<String, programClass>> result = chunks.get(chunks.size() - 1);
                        for (Map.Entry<String, Map<String, programClass>> channelEntry : result.entrySet()) { //For every channel data retrieved from the API, do the following

                            String cname = cm.getChannelName(channelEntry.getKey()); //Get the channel's name
                            rg.displayChannels(cname, channelEntry.getKey()); //Add that channel to the table to display it
                            Map<String, programClass> programs = channelEntry.getValue(); //List of programs in that channel retrieved from the API
                            if(programs != null)
                            { //If there are programs in the channel, hence programs != null
                                for (Map.Entry<String, programClass> programEntry : programs.entrySet()) { //For every program in the channel
                                    programClass program = programEntry.getValue(); //Get a variable containing info about that program
                                    String description = program.getDescription(); // Get the description from the program
                                    JLabel image = program.getDisplayImage(); // Get the image JLabel from the program
                                    String start = program.getStart(); //Get the start time of the program
                                    String end = program.getEnd(); //Get the end time of the program
                                    String name = program.getName(); //Get the name of the program
                                    
                                    // Assuming you have a method to display each program's description and image individually
                                    rg.displayPrograms(description, image, name, start, end); // Display the programs
                                }
                                rg.clearGui(); //Clear the GUI of it's all old displayed data
                            }
                            
                        }
                    }
                };
                sw.execute(); 
            }
        });
    
        dataUpdateTimer.setInitialDelay(0); // Start timer immediately
        dataUpdateTimer.start();
    }

Here’s the order in which I want my application to run:

  1. Display a message (JOptionPane)
  2. Clear the GUI
  3. Collect the data
  4. Display the data on screen

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật