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

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

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

You must login to ask a question.

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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

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

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:08:08+00:00 2026-06-11T00:08:08+00:00

I have written the following method in a class that inherits from the Thread

  • 0

I have written the following method in a class that inherits from the Thread class:

protected File createFile(String fileName){
        try {
            File file = new File(fileName);
            if(!file.exists())
                file.createNewFile();
            else{
                file.delete();
                file.createNewFile();
            }
            file.mkdirs();
            return file;
        }catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

It will be called from an Activity once the Thread has already started. If I do this from my Activity:

File logFile = mThread.createFile("/Logs/test.txt");
if(logFile!=null)
//do something
else
//do something else

Will it block until the file is created?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:08:10+00:00Added an answer on June 11, 2026 at 12:08 am

    Yes it will block.

    What counts is not the class from which the method is called, it is the run() method of the thread from which it is called. There is a high probability that

    File logFile = mThread.createFile("/Logs/test.txt");
    if(logFile!=null)
    //do something
    else
    //do something else
    

    is called from your activity run method (handled by android), and calling directly a method from another thread class will not by magic make this thread run this method.

    To ensure that you are not blocking your activity with this createFile method you should use message passing mechanism so that createFile is called within the run() method of your non-activity thread.

    See examples like the ones in this post for how to pass messages between threads. To sum up your activity thread will set a variable from your other thread. This thread periodically check this variable and execute actions depending on it. That’s the main idea but there is a lot to read on the web about this for thread safety and other problems that arise in these cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have written the following code class Program { static void Main(string[] args) {
I have a winforms app that includes the following class method: public aSqlQuery(SqlCommand pSqlCom,
i have the following class that writes to a file but is not working
I have written the following Utility class to get an instance of any class
I have written a following code to get just the file name without extension
I have written a small class, which reads out annotation from methods. Now I
I have written the following class: class myClass(object): def __init__(self): pass def foo(self, arg1,
I have written the following Java source file ( Hello.java ): package com; public
I have written a class in C# that is intended to offer the ability
I have the following code that defines a getParts method to find a given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.