A Java spring app is somehow killed without a trace

I have a java Spring boot app on Ubuntu that (mainly) runs fine.

But, if I go to a website that calls a Controller – data is fetched, the website is shown, but after a few seconds – the app is killed! (ps -ef doesn’t show the app, and the controllers are all dead).

I tried to catch the Spring close operation in this class:

@Slf4j
@Component
public class AlpacaServiceLifeCycle implements CommandLineRunner {
    @Override
    public void run(String... arg0) throws Exception {
        log.info("###START FROM THE LIFECYCLE###");
    }

    @PreDestroy
    public void onExit() {
        log.info("###STOP FROM THE LIFECYCLE###");
        new Exception().printStackTrace();
    }
}

And this class:

@Component
public class ContextClosedEventListener {
    @EventListener(ContextClosedEvent.class)
    public void onContextClosedEvent(ContextClosedEvent     contextClosedEvent) {
        System.out.println("ContextClosedEvent occurred     at millis: " + contextClosedEvent.getTimestamp());
        new Exception().printStackTrace();
    }
}

Also, the problematic class implements SmartLifecycle.

But still, nothing is shown!

If the app runs out of memory, an exception is thrown and file is created that tells me what happened. But not here (you can see that the data is saved in a table – the table size (with one row) is 0.02MB).

Could it be that somehow ubuntu kills the app?

The problematic controller:

@Slf4j
@RestController
@RequestMapping("/positions")
public class PositionsController implements SmartLifecycle {
    private static final String BODY_HTML_END = "t</body>n" +
            "</html>";
    private static final String alpacaLink = "https://app.alpaca.markets/trade/{*}";

    @Autowired
    private PositionsFetchService positionsFetchService;
    @Autowired
    private SellStocksDailyIndicatorScheduler sellStocksDailyIndicator;
    @Autowired
    private DailyPurchaseLogCache dailyPurchaseLogCache;

    @Resource
    private PositionTableRepository positionTableRepository;
    
    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = {MediaType.TEXT_HTML_VALUE})
    @ResponseStatus(HttpStatus.OK)
    public String list(@RequestParam(name = "soa", required = false) Boolean showOnlyAvailable) throws Exception {
        log.info("Positions called");
        
        if (positionTableRepository.findByFetchDate(LocalDate.now()) != null) {
            log.info("Fetching from DB");
            return positionTableRepository.findByFetchDate(LocalDate.now()).getTableStr();
        }
        
        Set<OutptOrderEntity> allOrders = dailyPurchaseLogCache.fetchAllOrders(false);
        StringBuilder theTable = new StringBuilder(CONSTANT_VISIBLE_HEADERS + "tt<table class="sortable">");
        theTable = new StringBuilder(theTable.toString().replace("*TITLE*", "Positions"));
        theTable.append("tt<th>#</th>n");
        theTable.append("tt<th>Created At</th>n");
        theTable.append("tt<th>symbol</th>n");
        theTable.append("tt<th>avg_entry_price</th>n");
        theTable.append("tt<th>current_price</th>n");
        theTable.append("tt<th>qty_available</th>n");
        theTable.append("tt<th>cost_basis</th>n");
        theTable.append("tt<th>market_value</th>n");
        theTable.append("tt<th>diff</th>n");
        theTable.append("tt<th>change_today</th>n");
        theTable.append("tt<th>lastday_price</th>n");
        theTable.append("tt<th>qty</th>n");
        theTable.append("tt<th>unrealized_pl</th>n");

        List<PositionEntity> positionEntities = positionsFetchService.fetch();

        for (int i = 0; i < positionEntities.size(); i++) {
            PositionEntity curr = positionEntities.get(i);
            if (curr.getAvg_entry_price() != null && curr.getCurrent_price() != null) {
                try {
                    String symbol = curr.getSymbol();
                    List<OutptOrderEntity> ordersOfSymbol = allOrders.stream().filter(s -> s.getSymbol().equals(symbol)).collect(Collectors.toList());
                    if (ordersOfSymbol.isEmpty()) {
                        log.warn("Symbol {} doesn't have data", symbol);
                        continue;
                    }
                    LocalDateTime createdAt = ordersOfSymbol.get(ordersOfSymbol.size() - 1).getCreated_at();
                    if (showOnlyAvailable && Float.parseFloat(curr.getQty_available()) > 0f) {
                        theTable.append(new TableData(false, alpacaLink.replace("{*}", curr.getSymbol()),
                                i + 1, createdAt, curr.getSymbol(), curr.getAvg_entry_price(), curr.getCurrent_price(), curr.getQty_available(), curr.getCost_basis(), curr.getMarket_value(),
                                Float.parseFloat(curr.getMarket_value()) - Float.parseFloat(curr.getCost_basis()), curr.getChange_today(), curr.getLastday_price(), curr.getQty(), curr.getUnrealized_pl()).
                                createString(Float.parseFloat(curr.getCurrent_price()) > Float.parseFloat(curr.getAvg_entry_price())));

                    } else if (!showOnlyAvailable) {
                        theTable.append(new TableData(false, alpacaLink.replace("{*}", symbol),
                                i + 1, createdAt, curr.getSymbol(), curr.getAvg_entry_price(), curr.getCurrent_price(), curr.getQty_available(), curr.getCost_basis(), curr.getMarket_value(),
                                Float.parseFloat(curr.getMarket_value()) - Float.parseFloat(curr.getCost_basis()), curr.getChange_today(), curr.getLastday_price(), 
                                curr.getQty(), curr.getUnrealized_pl()). createString(Float.parseFloat(curr.getCurrent_price()) > Float.parseFloat(curr.getAvg_entry_price())));
                    }
                } catch (Exception e) {
                    log.error(e.toString(), e);
                }
            }
        }

        theTable.append("ttt<script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>");
        theTable.append("ntt</table>n");
        theTable.append(BODY_HTML_END);
        log.info("Fetched all positions");

        positionTableRepository.save(new PositionsTableEntity(theTable.toString()));
        
        return theTable.toString();
    }

    @RequestMapping(value = "/sell_qty_exists", method = RequestMethod.GET, produces = {MediaType.TEXT_HTML_VALUE})
    @ResponseStatus(HttpStatus.OK)
    public void sellQtyExists() throws Exception {
        sellStocksDailyIndicator.scalpOnAllIndicators();
    }

    @Override public boolean isAutoStartup() {
        return false;
    }

    @Override public void stop(Runnable runnable) {
        new Exception().printStackTrace();
    }

    @Override public void start() {

    }

    @Override public void stop() {
        new Exception().printStackTrace();
    }

    @Override public boolean isRunning() {
        return false;
    }

    @Override public int getPhase() {
        return 0;
    }
} 

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